Skip to content

Instantly share code, notes, and snippets.

@galenweber
Created April 24, 2016 20:25
Show Gist options
  • Save galenweber/f4c93ff97270e7323d86f3ceef3e41b1 to your computer and use it in GitHub Desktop.
Save galenweber/f4c93ff97270e7323d86f3ceef3e41b1 to your computer and use it in GitHub Desktop.
var insertionSortwSplice = function(array) {
for (var i = 1; i < array.length; i++) {
for (var x = 0; x < i; x++ ) {
if (array[i] < array[x]) {
// Calling splice twice has got to be inefficient
array.splice(x,0,array[i]);
array.splice(i+1,1);
}
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment