Skip to content

Instantly share code, notes, and snippets.

@mjmeilahn
Last active June 16, 2023 23:34
Show Gist options
  • Save mjmeilahn/7b590cc510d0cdeac11280aedd4879ce to your computer and use it in GitHub Desktop.
Save mjmeilahn/7b590cc510d0cdeac11280aedd4879ce to your computer and use it in GitHub Desktop.
Logs all duplicate numbers in an array.
// 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