Created
March 25, 2018 05:23
-
-
Save yaminmhd/56873135c33c6df7dbb788dd0418da7a to your computer and use it in GitHub Desktop.
high order function reducer
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
| const votes = [ | |
| 'tacos', | |
| 'pizza', | |
| 'pizza', | |
| 'tacos', | |
| 'fries', | |
| 'ice cream', | |
| 'ice cream', | |
| 'pizza' | |
| ] | |
| const result = votes.reduce((tally,vote) => { | |
| if(!tally[vote]){ | |
| tally[vote] = 1 | |
| }else{ | |
| tally[vote] += 1 | |
| } | |
| return tally; | |
| }, {}) | |
| console.log(result) // {tacos: 2, pizza: 3, fries: 1, ice cream: 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment