Skip to content

Instantly share code, notes, and snippets.

@timurista
Last active January 11, 2019 14:26
Show Gist options
  • Save timurista/787cf67316a866d706af666a7d52f039 to your computer and use it in GitHub Desktop.
Save timurista/787cf67316a866d706af666a7d52f039 to your computer and use it in GitHub Desktop.
Remove dupes using es6 symbols
let testNews = [{...}];
function filterDupes(y) {
y = y.map(x => {
const combined = x.title+x.description;
const id = Symbol.for(combined.replace(/[^\w]+/g, ''))
return {...x, id}
})
var seen = {};
var arr = [];
for (let item of y) {
if (!seen[item.id]) {
seen[item.id] = true;
arr.push(item)
} else {
console.log('DUPE FOUND!', item.id)
}
}
return arr;
}
console.log('FILTERED ARR', filterDupes(testNews))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment