Skip to content

Instantly share code, notes, and snippets.

@mohshbool
Created January 29, 2019 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohshbool/669c6b9037a9fa5f7e142fc3dea4eb6c to your computer and use it in GitHub Desktop.
Save mohshbool/669c6b9037a9fa5f7e142fc3dea4eb6c to your computer and use it in GitHub Desktop.
// https://codeburst.io/javascript-array-distinct-5edc93501dc4
export const uniqueArray = (array) => {
console.log(array)
const result = []
const map = new Map()
for (const item of array) {
if(!map.has(item.imdbID)){
map.set(item.imdbID, true)
result.push({
imdbID: item.imdbID,
Title: item.Title,
Year: item.Year,
Poster: item.Poster
});
}
}
console.log(result)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment