Skip to content

Instantly share code, notes, and snippets.

@JimRottinger
Created May 7, 2019 03:04
Show Gist options
  • Save JimRottinger/1e5828bb29c8993a385ce14616d1a8f8 to your computer and use it in GitHub Desktop.
Save JimRottinger/1e5828bb29c8993a385ce14616d1a8f8 to your computer and use it in GitHub Desktop.
const insertionSort = (nums) => {
for (let i = 1; i < nums.length; i++) {
let j = i - 1
let tmp = nums[i]
while (j >= 0 && nums[j] > tmp) {
nums[j + 1] = nums[j]
j--
}
nums[j+1] = tmp
}
return nums
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment