Skip to content

Instantly share code, notes, and snippets.

@stutrek
Last active August 1, 2016 15:29
Show Gist options
  • Save stutrek/05449fcd795d8611218f83d6f04814cd to your computer and use it in GitHub Desktop.
Save stutrek/05449fcd795d8611218f83d6f04814cd to your computer and use it in GitHub Desktop.
// 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