Created
April 30, 2014 02:32
-
-
Save alloyking/d05bf3a2d663328df960 to your computer and use it in GitHub Desktop.
js array duplicates
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
Array.prototype.unique = function () { | |
var r = new Array(); | |
o:for(var i = 0, n = this.length; i < n; i++) | |
{ | |
for(var x = 0, y = r.length; x < y; x++) | |
{ | |
if(r[x]==this[i]) | |
{ | |
alert('this is a DUPE!'); | |
continue o; | |
} | |
} | |
r[r.length] = this[i]; | |
} | |
return r; | |
} | |
var arr = [1,2,2,3,3,4,5,6,2,3,7,8,5,9]; | |
var unique = arr.unique(); | |
alert(unique); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment