The goal is to create To Do App that will have the following functionalities:
- users can sign up, log in and log out,
- users can create, list, edit and delete projects and
- projects will have tasks.
let convertToSnake = (camelCased) => { | |
let lettersArr = [...camelCased]; | |
let snaked_str = ''; | |
lettersArr.forEach(letter => { | |
if(letter !== letter.toUpperCase()){ | |
snaked_str += letter | |
} else { | |
snaked_str += `_${letter.toLowerCase()}` | |
} | |
}) |
// this solution is the most efficient because it walks the array only once and | |
// it doesn't use any helper methods | |
const firstNonRepeatingLetterA = (str) => { | |
let theObj = {}; | |
for(let i = 0; i< str.length; i++){ | |
if(theObj[str[i]]){ | |
theObj[str[i]]+=1; | |
} else { | |
theObj[str[i]] = 1; | |
} |
Very often you will see that length - 1
is being used and you might ask yourself why is that.
Here is an example that will demo when and why you should use it and what is the alternative way.
Let's take variable firstName
and has the length 4.
const firstName = "maya";
const someString = "hey there hey what up what" | |
const howMany = (blah) => { | |
let arrOfWords = blah.split(" "); | |
const mappedObj = {}; | |
for(let i=0; i<arrOfWords.length; i++){ | |
if(mappedObj[arrOfWords[i]]){ | |
mappedObj[arrOfWords[i]]++ | |
} else { | |
mappedObj[arrOfWords[i]]=1 |
console.log("------------ iteration 1 ------------"); | |
// Iteration 1: Names and Input | |
// 1.1 Create a variable hacker1 with the driver's name. | |
let hacker1 = "kevin"; | |
// 1.2 Print "The driver's name is XXXX". | |
console.log(`hacker1's name is ${hacker1}`); | |
// 1.3 Create a variable hacker2 with the navigator's name. |
// new SortedList should create a new object from the SortedList class | |
// The object should have a items and length property | |
// items should be an array | |
// length should be the number of elements in the array | |
class SortedList { | |
constructor(){ | |
this.items = []; | |
this.length = this.items.length; | |
} |