Skip to content

Instantly share code, notes, and snippets.

@nuweb
Last active August 29, 2015 14:07
Show Gist options
  • Save nuweb/7e304401a344dc1b5282 to your computer and use it in GitHub Desktop.
Save nuweb/7e304401a344dc1b5282 to your computer and use it in GitHub Desktop.
Unique letters in a string using reduce
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