Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function countLetters(word){
- let counter = {};
- for(let i = 0; i < word.length; i++){
- let position = word.charAt(i)
- if(!counter[position] && position !== " "){
- counter[position] = 1;
- }
- else if(counter[position]){
- counter[position] = counter[position] += 1
- // counter[position] += 1 (this also works)
- }
- console.log(counter)
- }
- }
- countLetters('hello world')
Add Comment
Please, Sign In to add comment