Created
October 24, 2017 05:34
-
-
Save tasandberg/1bc109993ddd620f10bb433afff53363 to your computer and use it in GitHub Desktop.
Remove duplicates from array of Mongo ObjectIDs
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
/** | |
* Given many arrays of ObjectIDs, return a unique list | |
* | |
* @params objectIDs {Array<ObjectID>} | |
* @returns | |
*/ | |
module.exports = function dedupeIDs(objectIDs) { | |
const ids = {} | |
objectIDs.forEach(_id => (ids[_id.toString()] = _id)) | |
return Object.values(ids) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work for me.
The first line is the log of the ObjectIDs of a property of a document that I get from the DB.
The second line is the result of a concat method in which I merge the array from line 1 with an array with another ObjectID.
The third line is the result of your function, which seemingly gives me the wrong result. 🙁