Skip to content

Instantly share code, notes, and snippets.

@darkcris1
Created January 3, 2021 11:43
Show Gist options
  • Save darkcris1/e8322dee2e3ead66013c94d0c07aeeee to your computer and use it in GitHub Desktop.
Save darkcris1/e8322dee2e3ead66013c94d0c07aeeee to your computer and use it in GitHub Desktop.
Insertion Sort Alagorithm
function insertionSort(arr) {
for (let i = 1; i < arr.length; i++) {
for (let j = i; j > 0; j--) {
if (arr[i] < arr[j - 1]) {
const temp = arr[i]
arr[i] = arr[j - 1]
arr[j - 1] = temp
i--
}
}
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment