Skip to content

Instantly share code, notes, and snippets.

@danielvanc
Created March 1, 2022 13:46
Show Gist options
  • Save danielvanc/b70584ca5655fe6b2d03601c8840a414 to your computer and use it in GitHub Desktop.
Save danielvanc/b70584ca5655fe6b2d03601c8840a414 to your computer and use it in GitHub Desktop.
Unique names with reduce()
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