Last active
November 2, 2019 17:52
-
-
Save sandrabosk/72433e80d08721fe205101c5884dcc4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
return mappedObj; | |
} | |
howMany(someString); | |
// { | |
// hey: 2, | |
// there: 1, | |
// what: 2, | |
// up: 1 | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment