Skip to content

Instantly share code, notes, and snippets.

@hiroshi-maybe
Created February 3, 2013 09:13
Show Gist options
  • Save hiroshi-maybe/4701011 to your computer and use it in GitHub Desktop.
Save hiroshi-maybe/4701011 to your computer and use it in GitHub Desktop.
Comb sort implemented with Javascript.
var combSort = function (array) {
var interval = Math.floor(array.length/1.3);
while (interval > 0) {
for(var i=0; i+interval<array.length; i+=1) {
if (array[i] > array[i+interval]) {
var small = array[i+interval];
array[i+interval] = array[i];
array[i] = small;
}
}
interval = Math.floor(interval/1.3);
}
return array;
};
console.log(combSort([8,4,3,7,6,5,2,1]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment