Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Last active January 10, 2023 20:14
Show Gist options
  • Save Angelfire/d8cd85172097e42bc0ae776e7100b023 to your computer and use it in GitHub Desktop.
Save Angelfire/d8cd85172097e42bc0ae776e7100b023 to your computer and use it in GitHub Desktop.
Remove Duplicates
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