编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
// 快排
function quickSort(arr) {
    if(arr.length == 1) {
        return arr
    }
    let temp = arr.shift()
    let left = [], right = []
    arr.forEach(item => {
        if(temp > item) {
            left.push(item)
        } else {
            right.push(item)
        }
    })
    return quickSort(left).concat([temp], quickSort(right))
}

console.log(quickSort([8,3,4,2,10,5,3]))

// 冒泡排序

function sort(arr) {
    for(let i = arr.length; i > 0; i--) {
        for (let j = 0; j < i; j++)
        if (arr[j] > arr[j+1]) {
            let temp = arr[j]
            arr[j] = arr[j+1]
            arr[j+1] = temp
        }
    }
    return arr
}

console.log(sort([8,3,4,2,10,5,3]))