Created
September 24, 2022 21:17
-
-
Save javierd79/58527002f23ce08fe3981f302405384a to your computer and use it in GitHub Desktop.
Function to count how many elements are duplicates in an Array
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
const countDuplicate = (array) => { | |
let object = array.reduce((prev, cur) => ((prev[cur] = prev[cur] + 1 || 1), prev), {}) | |
console.log(object); | |
} | |
countDuplicate(['test', 'test', 'test2']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment