Created
November 6, 2012 21:31
-
-
Save abozhilov/4027724 to your computer and use it in GitHub Desktop.
Reordering 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(sortedArr) { | |
var arr = [], | |
i = -1, | |
j = -1, | |
len = sortedArr.length; | |
while (++i < len) { | |
if (arr[j] !== sortedArr[i]) { | |
arr[++j] = sortedArr[i]; | |
} | |
} | |
return arr; | |
} | |
console.log(unique([1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 6])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment