Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created April 4, 2018 22:06
Show Gist options
  • Save dmitryshelomanov/64807202f91ad22a41cb9ddc70055d53 to your computer and use it in GitHub Desktop.
Save dmitryshelomanov/64807202f91ad22a41cb9ddc70055d53 to your computer and use it in GitHub Desktop.
const data = [4, 3, 5, 0, 1, 10, 8, 2, 9]
function insertedSort(data) {
for (let i = 0; i < data.length; i++) {
for (let j = i; j > 0 && data[j] < data[j - 1]; j--) {
[data[j], data[j - 1]] = [data[j - 1], data[j]]
}
}
return data
}
function bubbleSort(data) {
for (let i = data.length; i > 0; i--) {
for (let j = 0; j < i; j++) {
if (data[j] > data[j + 1]) {
[data[j], data[j + 1]] = [data[j + 1], data[j]]
}
}
}
return data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment