Created
January 3, 2021 11:43
-
-
Save darkcris1/e8322dee2e3ead66013c94d0c07aeeee to your computer and use it in GitHub Desktop.
Insertion Sort Alagorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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