Skip to content

Instantly share code, notes, and snippets.

@jkusachi
Created February 11, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkusachi/90acba71f08df49efa97 to your computer and use it in GitHub Desktop.
Save jkusachi/90acba71f08df49efa97 to your computer and use it in GitHub Desktop.
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