Created
January 14, 2018 21:52
-
-
Save davidnagli/be72fa79e4ac6d6bff3ed0af240ebf18 to your computer and use it in GitHub Desktop.
cdup-js : count duplicates in a javascript array (find the count of each unique element in an array) with this simple, easy, and FAST one liner
This file contains 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
// Readable version: | |
array.reduce((countsMap, item) => countsMap.set(item, countsMap.get(item) + 1 || 1), new Map) | |
// Minified version: | |
array.reduce((a,b)=>a.set(b,a.get(b)+1||1),new Map) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment