Created
July 8, 2018 16:34
-
-
Save andreasvirkus/166c5db00dd509150acb9b7d391981f4 to your computer and use it in GitHub Desktop.
Takes an array and returns a tally of its unique items
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 nums = [3, 5, 6, 82, 1, 4, 3, 5, 82] | |
const result = nums.reduce((tally, amt) => { | |
tally[amt] ? tally[amt]++ : tally[amt] = 1 | |
return tally | |
}, {}) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment