Created
February 11, 2016 18:39
-
-
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.
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
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