Skip to content

Instantly share code, notes, and snippets.

@darkcris1
Created January 3, 2021 11:41
Show Gist options
  • Save darkcris1/60086b6beac984e6a5878c4b8123fafa to your computer and use it in GitHub Desktop.
Save darkcris1/60086b6beac984e6a5878c4b8123fafa to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm
function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 1; j < arr.length; j++) {
if (arr[j] < arr[j - 1]) {
const temp = arr[j - 1]
arr[j - 1] = arr[j]
arr[j] = temp
}
}
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment