Snippets Collections
function bubbleSort(arr){
  let len = arr.length;
  let cost = 0;
  
  for(let i=0; i<len; i++){
    for(let j=0; j<len-1; j++){
      if(arr[j] > arr[j+1]){
        swap(arr, j, j+1);
      }
    }
  }
  return arr
}

let unsortedArr = [0, 5, 6, 8, 2, 1, 3, 7, 4, 10, 12, 11]

console.log(bubbleSort(unsortedArr))
star

Mon May 23 2022 23:08:49 GMT+0000 (Coordinated Universal Time)

#javascript #sort #bubble

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension