Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Created December 18, 2018 02:04
Show Gist options
  • Select an option

  • Save rajatk16/4904fb0e725eda47073b68794bf326d5 to your computer and use it in GitHub Desktop.

Select an option

Save rajatk16/4904fb0e725eda47073b68794bf326d5 to your computer and use it in GitHub Desktop.
insertionSort = (array) => {
for (outer = 1; outer < array.length; outer++) {
for (inner = 0; inner < outer; inner++) {
console.log(array.join(' '))
if (array[outer] < array[inner]) {
const [element] = array.splice(outer, 1)
array.splice(inner, 0, element)
}
}
}
console.log(array.join(' '))
return array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment