Created
April 29, 2020 09:18
-
-
Save olegpolyakov/be14b7c3647af0300ef2e269453dec82 to your computer and use it in GitHub Desktop.
dedupMerge
This file contains hidden or 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 people = [ | |
{ | |
department: "Directing", | |
id: 20561, | |
job: "Director", | |
name: "James Gray" | |
}, | |
{ | |
department: "Writing", | |
id: 20561, | |
job: "Screenplay", | |
name: "James Gray" | |
}, | |
{ | |
department: "Writing", | |
id: 1750900, | |
job: "Screenplay", | |
name: "Ethan Gross" | |
}, | |
{ | |
department: "Writing", | |
id: 20561, | |
job: "Dresser", | |
name: "James Gray" | |
} | |
]; |
This file contains hidden or 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
function dedupMerge(items, map) { | |
return Object.values(people.reduce((result, item) => { | |
result[item.id] = !result[item.id] ? item : map(result[item.id], item); | |
return result; | |
}, {})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment