Last active
January 10, 2023 20:14
-
-
Save Angelfire/d8cd85172097e42bc0ae776e7100b023 to your computer and use it in GitHub Desktop.
Remove Duplicates
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
function removeDuplicates(arr) { | |
return arr.filter((el, idx) => arr.indexOf(el) === idx) | |
} | |
function removeDuplicates(numbers) { | |
return numbers.reduce((accumulator, currentValue) => { | |
if(accumulator.indexOf(currentValue) === -1) { | |
accumulator.push(currentValue) | |
} | |
return accumulator | |
}, []); | |
} | |
function allUnique(numbers) { | |
return numbers.reduce((accumulator, currentValue, index) => { | |
if (numbers.indexOf(currentValue) !== index) return false | |
return accumulator | |
}, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment