Last active
January 21, 2020 08:16
-
-
Save wiedymi/08e931fc6d0e281a52432c6c3d371339 to your computer and use it in GitHub Desktop.
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 removeDublication(array, cb) { | |
if (!array) { | |
throw new Error("No array has been provided."); | |
} | |
if (!cb) { | |
throw new Error("No callback has been provided."); | |
} | |
return array.reduce( | |
(acc, value) => { | |
const isExist = acc.some(v => cb(v, value)); | |
if (!isExist) { | |
acc = [...acc, value]; | |
} | |
return acc; | |
}, | |
[array[0]] | |
); | |
} |
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
console.log( | |
removeDublication([{ id: 1 }, { id: 1 }, { id: 1 }], (v, val) => { | |
return v.id !== val; | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment