Last active
March 5, 2019 14:48
-
-
Save tigrouind/2d303f24f8f3aef4fe73eef546941498 to your computer and use it in GitHub Desktop.
move duplicate items next to each other
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
function sort(a) { | |
var n = a.length; | |
for (var j = 0; j < n - 2; j++) { | |
for (var i = j + 1; i < n; i++) { | |
if (a[i] == a[j]) { | |
//swap | |
if (a[i] != a[j + 1]) { | |
var tmp = a[j + 1]; | |
a[j + 1] = a[i]; | |
a[i] = tmp; | |
} | |
j++; | |
} | |
} | |
} | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment