Last active
January 11, 2019 14:26
-
-
Save timurista/787cf67316a866d706af666a7d52f039 to your computer and use it in GitHub Desktop.
Remove dupes using es6 symbols
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
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