Skip to content

Instantly share code, notes, and snippets.

@amite
Created April 22, 2017 09:16
Show Gist options
  • Save amite/53a6b562d0d18b4f9dd49508090699bf to your computer and use it in GitHub Desktop.
Save amite/53a6b562d0d18b4f9dd49508090699bf to your computer and use it in GitHub Desktop.
Names statistics solution
```
var names = ['Alice', 'Bob', 'Tiff', "Sonny", 'Bruce', 'Alice', "Sonny"];
//output shoule be { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
var initialValue = {};
var reducer = (names, stats) => {
(!names[stats]) ? names[stats] = 1
: names[stats] = names[stats] + 1;
return names;
};
var result = names.reduce(reducer, initialValue);
console.clear()
console.log(result);
```
ES6 friendly version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment