Skip to content

Instantly share code, notes, and snippets.

@taishikato
Created June 5, 2020 18:01
Show Gist options
  • Save taishikato/acc778aad51da33d6034c98da71ac273 to your computer and use it in GitHub Desktop.
Save taishikato/acc778aad51da33d6034c98da71ac273 to your computer and use it in GitHub Desktop.
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