Skip to content

Instantly share code, notes, and snippets.

@ramzesucr
Created July 12, 2017 10:18
Show Gist options
  • Save ramzesucr/c97be169c19c4d8d15a8e112df6dcd01 to your computer and use it in GitHub Desktop.
Save ramzesucr/c97be169c19c4d8d15a8e112df6dcd01 to your computer and use it in GitHub Desktop.
Bubble sort
const bubbleSort = (input) => {
let data = input.slice()
for(var i = 0; i < data.length; i++) {
for(var j = 1; j < data.length - i; j++) {
if(data[j - 1] > data[j]) exchange(data, j - 1, j)
}
}
return data
}
const exchange = (list, left, right) => {
const mid = list[left]
list[left] = list[right]
list[right] = mid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment