Bubble Sort
Bubble sort is one of a few different sorting algorithms. In its basic form it takes in array of random integers and returns an array of those numbers sorted from least to greatest. It does this by “bubbling” the largest number to the back of the array through iteration.
Let’s unpack what’s going on here. First we need to loop through the array. While the first for loop is iterating through each element of the array we need a second loop to check each element side by side. We then check if the first element in the pair is greater than the one in front. We then use a bit of ES6 to swap the elements and continue until the array is sorted. Finally we return the sorted array and we have achieved bubble sort!
Resources: