Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Takes a collection of data and removes any duplicates, based on key, thare are not null. If the key value is null, it is not filtered out.
var deDupeNonNull = function(data, key){
var used = [];
return _.reduce(data, function(cur, data){
if(!!data[key] && !_.includes(used, data[key])){
used.push(data[key]);
cur.push(data);
}
else if(!data[key]) {
cur.push(data);
}
return cur;
}, []);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.