Created
January 5, 2020 22:03
-
-
Save cozzbie/9570c081b7af53a55085a7187c8900d3 to your computer and use it in GitHub Desktop.
In-place insert sort.
This file contains 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
const insertSort = array => { | |
for(let i = 1; i < array.length; i++) { | |
const el = array[i]; | |
let j = i - 1; | |
while(j >= 0 && el < array[j]){ | |
array[i--] = array[j]; | |
array[j] = el; | |
j--; | |
} | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment