Created
December 4, 2012 19:25
-
-
Save deleteme/4207746 to your computer and use it in GitHub Desktop.
unique new york
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
function unique(array){ | |
var unique = []; | |
for (var i = 0, l = array.length; i < l; i++){ | |
if (unique.indexOf(array[i]) === -1) | |
unique.push(array[i]); | |
} | |
return unique; | |
} |
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
function unique(array){ | |
var unique = []; | |
for (var i = 0, l = array.length; i < l; i++){ | |
if (!unique.join(',').match(new RegExp('[,]' + array[i]))) | |
unique.push(array[i]); | |
} | |
return unique; | |
} |
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
function unique(array){ | |
var uniqueObject = {}; | |
for (var i = 0, l = array.length; i < l; i++) { | |
uniqueObject[array[i]] = array[i]; | |
} | |
var unique = []; | |
for (var key in uniqueObject){ | |
if (uniqueObject.hasOwnProperty(key)) unique.push(key); | |
} | |
return unique; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment