Created
June 5, 2020 18:01
-
-
Save taishikato/acc778aad51da33d6034c98da71ac273 to your computer and use it in GitHub Desktop.
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
const insertionSort = (nums) => { | |
const arr = nums.toString().split(''); | |
for (let i = 1; i < arr.length; i++) { | |
let j = i - 1 | |
let tmp = arr[i] | |
while (j >= 0 && arr[j] > tmp) { | |
arr[j + 1] = arr[j] | |
j-- | |
} | |
arr[j + 1] = tmp | |
} | |
return arr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment