Skip to content

Instantly share code, notes, and snippets.

@tigrouind
Last active March 5, 2019 14:48
Show Gist options
  • Save tigrouind/2d303f24f8f3aef4fe73eef546941498 to your computer and use it in GitHub Desktop.
Save tigrouind/2d303f24f8f3aef4fe73eef546941498 to your computer and use it in GitHub Desktop.
move duplicate items next to each other
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