Skip to content

Instantly share code, notes, and snippets.

@AaronFlower
Last active October 27, 2017 02:26
Show Gist options
  • Save AaronFlower/5b60e5f841fccddee1e2e4c62adb8127 to your computer and use it in GitHub Desktop.
Save AaronFlower/5b60e5f841fccddee1e2e4c62adb8127 to your computer and use it in GitHub Desktop.
Insertion sort javascript version
function insertionSort(data)
{
for(let i = 1; i < data.length; ++i) {
let j = i
while(j > 0 && data[j] < data[j - 1]) {
let tmp = data[j]
data[j] = data[j - 1]
data[j - 1] = tmp
j --
}
}
}
data = Array.from({length: 20}).map(() => Math.floor(Math.random() * 20))
console.log(data)
insertionSort(data)
console.log(data)
@AaronFlower
Copy link
Author

AaronFlower commented Oct 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment