Last active
August 1, 2016 15:29
-
-
Save stutrek/05449fcd795d8611218f83d6f04814cd 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
// in place array unique | |
function unique (arr) { | |
var i = 0; | |
var end = arr.length - 1; | |
while (i < end) { | |
var item = arr[i]; | |
var index = arr.lastIndexOf(item, end); | |
if (index > i) { | |
arr[i] = arr[end]; | |
end -= 1; | |
} else { | |
i += 1; | |
} | |
} | |
arr.length = end + 1; | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment