2-min Bubble Sort(of pointless?) — Algorithm Basics —

A Bubble. It moves up?
function swap(arr, index1, index2){}
function swap(arr, index1, index2){
[arr[index1], arr[index2]] = [arr[index2],arr[index1]
Party Time, we are almost there!
function bubbleSort(arr){
//we are going to set out i value to the array.length so that we are
//not going over the full length of the array every iteration.

for(let i = arr.length; i>0;i--){
for(let j = 0; j<i; j++){

//if the current index is greater than the next index, we Swap //<strong/>
if(arr[j]> arr[j+1]){
swap(arr, j, j+1);



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store