Created
March 13, 2020 14:47
-
-
Save qodirovshohijahon/f2010b1f80eb99f38ed6fcfd38e10fc6 to your computer and use it in GitHub Desktop.
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
function insert(arr) { | |
for(let i = 1; i < arr.length; i++) { | |
let key = arr[i]; | |
let j = i - 1; | |
while(j >= 0 && arr[j] > key) { | |
arr[j+1] = arr[j]; | |
j--; | |
} | |
arr[j+1] = key; | |
} | |
return arr; | |
} | |
und |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment