Skip to content

Instantly share code, notes, and snippets.

@davidryanhuff
Created July 22, 2017 00:36
Show Gist options
  • Save davidryanhuff/c78735ed995b28ffd8e8af45ffa04334 to your computer and use it in GitHub Desktop.
Save davidryanhuff/c78735ed995b28ffd8e8af45ffa04334 to your computer and use it in GitHub Desktop.
const array = [ 'NORTH', 'SOUTH', 'SOUTH', 'EAST', 'WEST', 'NORTH', 'WEST' ]
const count = array.sort().reduce((counter, item) => {
counter[item] = counter.hasOwnProperty(item) ? counter[item] + 1 : 1;
return counter;
}, {})
console.log(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment