untitled notebook

node v10.23.3
version: 1.0.0
endpointsharetweet
//BUBBLE SORT ALGORITHM let givenArray = [100,29,1,0,110,23,33,2,9]; function bubbleSortAlgo(arr) { function swap(arr, index1, index2) { [arr[index1], arr[index2]] = [arr[index2], arr[index1]] } let isSwap; for(let i = arr.length; i > 0 ; i--) { isSwap = true; for(let j = 0; j < i - 1; j++) { if(arr[j] > arr[j+1]) { swap(arr, j, j+1) isSwap = false; } } if(isSwap) break; } return arr; } console.log(bubbleSortAlgo(givenArray));
Loading…

no comments

    sign in to comment