const quickSort = (arr) => { if (!arr.length) { return arr; } const pivot = arr[0]; const minArr = arr.filter((arr) => arr < pivot); // pivotより小さい配列を作成 const maxArr = arr.filter((arr) => arr > pivot); // pivotより大きい配列を作成 return [...quickSort(minArr), pivot, ...quickSort(maxArr)]; // pivot を中心に配列を再構築 };
実行結果