Browse files

Create bubblesort.js

  • Loading branch information...
jlboba committed Jan 13, 2020
1 parent cbfc64e commit ce07d6fc0e78a8824fc7ef9f443347f5a0a5be6e
Showing with 19 additions and 0 deletions.
  1. +19 −0 bubblesort.js
@@ -0,0 +1,19 @@
function bubbleSort(array) {
// Make some sort of loop that keeps happening if there were any swaps
// that happened this turn

// reset swapHappened to false each time so we can detect if a swap
// happened in this specific iteration.

// Make another loop (inside the first one) to go through one
// round of swapping from the start of the list to the end

// Inside inner loop:
// compare each pair of elements near each other
// swap them if the bigger one was at a lower index.

// Make sure to keep track of whether a swap happened!

// After both loops have exited, remember to return the array
return array;

0 comments on commit ce07d6f

Please sign in to comment.