Skip to content

Instantly share code, notes, and snippets.

@OlegKorn
Created October 10, 2022 06:17
Show Gist options
  • Save OlegKorn/5bb717178e690b16c6976ed0ed2cd9d4 to your computer and use it in GitHub Desktop.
Save OlegKorn/5bb717178e690b16c6976ed0ed2cd9d4 to your computer and use it in GitHub Desktop.
bubble sort JS
function bubbleSort() {
a = [33, 2, 3345, 34456456, 3, 3434, 41, 314, 34, 34445]
for (var i = 0; i < a.length; i++) {
var swapped = false
for (var j = 0; j < a.length - 1; j++) {
if (a[j] > a[j+1]) {
var temp
temp = a[j]
a[j] = a[j+1]
a[j+1] = temp
temp = null
swapped = true
}
}
if (!swapped) {
break
}
console.log(a)
}
}
bubbleSort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment