Skip to content

Instantly share code, notes, and snippets.

@herber
Last active October 26, 2017 20:10
Show Gist options
  • Save herber/8e949021fe6910ba84cee6d492f774de to your computer and use it in GitHub Desktop.
Save herber/8e949021fe6910ba84cee6d492f774de to your computer and use it in GitHub Desktop.
A simple bubble sort function.
const bubbleSort = (arr) => {
for (let i = arr.length - 1; i >= 0; i--){
for(let j = 1; j <= i; j++){
if(arr[j - 1] > arr[j]){
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