Created
March 4, 2017 19:56
-
-
Save clohr/ebbfdbb3ae1b43711d9867a31a65a36f to your computer and use it in GitHub Desktop.
Return duplicates within a JS array
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 count = names => names.reduce((acc, name) => Object.assign(acc, {[name]: (acc[name] || 0) + 1}), {}) | |
| const duplicates = dict => Object.keys(dict).filter((a) => dict[a] > 1) | |
| const getDuplicates = vals => duplicates(count(vals)) | |
| export default getDuplicates |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternate version: