Bubble sort
Aashish Panchal
Posted on October 16, 2020
function bubbleSort(arr){
for(var i = 0; i < arr.length; i++){
for(var j = 0; j < arr.length; j++){
console.log(arr, "--" ,arr[j], "<<--SWAP TO-->> ", arr[j+1]);
if(arr[j] > arr[j+1]){
// SWAP....!!!!
var temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
return arr;
}
bubbleSort([87,65,45,1])
💖 💪 🙅 🚩
Aashish Panchal
Posted on October 16, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
opensource RoSctober Fest Wrap-Up: A Month of Code, Community, and Sloth Points! 🦥
November 13, 2024
hacktoberfest ✨ From Contributor to Core Project Maintainer: My Open Source Journey ✨
October 11, 2024
hacktoberfestchallenge My Hacktoberfest 2024 Journey: A Month of Code, Growth, and Unforgettable Lessons 🚀
November 1, 2024