Skip to content

Instantly share code, notes, and snippets.

@ZackFox
Last active March 28, 2019 07:11
Show Gist options
  • Save ZackFox/91c33c17b6cf8934718c2346d3ff8864 to your computer and use it in GitHub Desktop.
Save ZackFox/91c33c17b6cf8934718c2346d3ff8864 to your computer and use it in GitHub Desktop.
bubble sort
for(let i = 0; i < arr.length; i++){
for(let j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
const temp = arr[i];
arr[i] = arr[j]
arr[j] = temp;
}
}
}
for(let i = arr.length-1; i > 0; i--){
for(let j = 0; j < i; j++){
if(arr[j] > arr[j+1]){
const temp = arr[j];
arr[j] = arr[j+1]
arr[j+1] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment