Created
July 22, 2016 17:39
-
-
Save che-wf/f1c616a32ee4d642691792eebdc4257b to your computer and use it in GitHub Desktop.
This is an efficient approach to finding duplicates in an array or eliminating duplicates from an array.
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
var a = ["a","a","b","c","c"]; | |
var dupes = a.filter((value,index,self)=>{ return (self.indexOf(value) !== index )}); | |
var cleanArray = a.filter((value,index,self)=>{ return (self.indexOf(value) === index )}); | |
console.log(dupes); | |
console.log(cleanArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment