Skip to content

Instantly share code, notes, and snippets.

@Aleksey-Danchin
Created July 15, 2015 09:04
Show Gist options
  • Save Aleksey-Danchin/6cdb2ab3af88925aff06 to your computer and use it in GitHub Desktop.
Save Aleksey-Danchin/6cdb2ab3af88925aff06 to your computer and use it in GitHub Desktop.
Sort by Insert Method.
function insertSort (array) {
for (var i = 1; i < array.length; i++) {
var key = array[i], j = i - 1;
while (j > -1 && array[j] > key)
array[j + 1] = array[j--];
array[j + 1] = key;
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment