标签:let UNC const style ons push func res nbsp
function quickSort (arr) { if (arr.length === 0) { return []; } let left = []; let right = []; let pivot = arr[0]; for (let index = 1; index < arr.length; index++) { const element = arr[index]; if (element < pivot) { left.push(element); } else { right.push(element); } } return [...quickSort(left), pivot, ...quickSort(right)]; } const arr = [2, 3, 43, 5, 1, 7, 6, 3, 22]; console.log(‘排序之前‘, arr); const res = quickSort(arr); console.log(‘排序之后‘, res);
排序之前 [ 2, 3, 43, 5, 1, 7, 6, 3, 22 ] 排序之后 [ 1, 2, 3, 3, 5, 6, 7, 22, 43 ]
标签:let UNC const style ons push func res nbsp
原文地址:https://www.cnblogs.com/xiaosongJiang/p/10915385.html