Last active
August 29, 2015 14:07
-
-
Save nuweb/7e304401a344dc1b5282 to your computer and use it in GitHub Desktop.
Unique letters in a string using reduce
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
function getLetterCount(arr){ | |
return arr.reduce(function(prev,next){ | |
prev[next] = (prev[next] + 1) || 1; | |
console.log(prev[next]); | |
return prev; | |
},{}); | |
} | |
var str = "dfdddf"; | |
console.log(getLetterCount(str.split(''))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment