冒泡排序
let arr = [2,7,4,1,3,6,5,9,0,8]
let temp = ''
for (let i = 0; i < arr.length; i++){
for(let j = i; j < arr.length; j++){
if ( arr[i] > arr[j] ) {
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
}
}
console.log(arr) // [0,1,2,3,4,5,6,7,8,9]
編輯:--ns868