Open fudx opened 1 year ago
function bubbleSort(arr) {
for(let i = 0; i < arr.length; i++) {
for(let j = 0; j < arr.length - i; j++) {
if(arr[j] > arr[j+1]) {
[arr[j], arr[j+1]] = [arr[j+1], arr[j]]
}
}
}
return arr
}
const test = [2,7,4,1,23]
console.log(bubbleSort(arr)) // 1,2,4,7,23