Created
October 9, 2014 13:31
-
-
Save colintoh/9944c8d8941e0625e3be to your computer and use it in GitHub Desktop.
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 arr = [2,3,4,5,2,4]; | |
//Without Set | |
var tempArr = arr.filter(function(item,index){ | |
return arr.indexOf(item) == index; | |
}); | |
console.log(tempArr.length); //4 | |
//With Set | |
var set = new Set(); | |
arr.forEach(function(item){ | |
set.add(item); | |
}); | |
console.log(set.size); //4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment