Last active
June 16, 2023 23:34
-
-
Save mjmeilahn/7b590cc510d0cdeac11280aedd4879ce to your computer and use it in GitHub Desktop.
Logs all duplicate numbers 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
// Log all duplicate numbers in an array. | |
const arr = [1,3,2,5,6,7,3,3,1,4,4] | |
const logDuplicates = arr => { | |
const results = [] | |
arr.map(num => { | |
const dupe = arr.filter(i => i === num).length > 1 | |
if (dupe === true && !results.includes(num)) { | |
results.push(num) | |
} | |
}) | |
return results | |
} | |
console.log(logDuplicates(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment