Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created July 8, 2018 16:34
Show Gist options
  • Save andreasvirkus/166c5db00dd509150acb9b7d391981f4 to your computer and use it in GitHub Desktop.
Save andreasvirkus/166c5db00dd509150acb9b7d391981f4 to your computer and use it in GitHub Desktop.
Takes an array and returns a tally of its unique items
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