Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Created December 29, 2019 19:27
Show Gist options
  • Save risingBirdSong/696a3515d3b4472f6f49abcde2af6346 to your computer and use it in GitHub Desktop.
Save risingBirdSong/696a3515d3b4472f6f49abcde2af6346 to your computer and use it in GitHub Desktop.
function duplicateCounta(text : string){
return text
.toLowerCase()
.split('')
.reduce(function(a, l) {
a[l] = a[l] ? a[l]+1 : 1;
if(a[l] === 2) a.count++;
return a;
}, {count:0}).count;
}
// i solved this one in a similiar way using reduce, but this other solution from a code warrior is really good, had to save it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment