Guest User

Untitled

a guest
Jan 16th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. function countLetters(word){
  2. let counter = {};
  3. for(let i = 0; i < word.length; i++){
  4. let position = word.charAt(i)
  5. if(!counter[position] && position !== " "){
  6. counter[position] = 1;
  7. }
  8. else if(counter[position]){
  9. counter[position] = counter[position] += 1
  10. // counter[position] += 1 (this also works)
  11. }
  12. console.log(counter)
  13. }
  14. }
  15.  
  16. countLetters('hello world')
Add Comment
Please, Sign In to add comment