Created
March 1, 2022 13:46
-
-
Save danielvanc/b70584ca5655fe6b2d03601c8840a414 to your computer and use it in GitHub Desktop.
Unique names with reduce()
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 namesOfPeople = [ | |
"Dan", | |
"Hannah", | |
"Cameron", | |
"Nash", | |
"Dan", | |
"Hannah", | |
"Cameron", | |
"Nash", | |
"Dan", | |
"Hannah", | |
"Cameron", | |
"Nash", | |
"Charlie", | |
"Ivy", | |
"George", | |
]; | |
const uniqueNames = namesOfPeople.reduce((prev, curr) => { | |
if (!prev.includes(curr)) { | |
prev.push(curr); | |
} | |
return prev; | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment