let arr = [];
for (let i = 0; i < 10; i++) {
arr.push(parseInt(Math.random() * 10))
}
console.log(arr);
let arrRepeat = [];
function quickSort(arr) {
if (arr.length <= 1) {
return arr
}
let index = Math.floor(arr.length / 2),
base = arr.splice(index, 1)[0],
left = [],
right = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] > base) {
right.push(arr[i])
} else {
left.push(arr[i])
}
if (arr[i] == base) {
arrRepeat.push(arr[i])
}
}
return quickSort(left).concat([base], quickSort(right));
}
let arrsort = quickSort(arr);
console.log(arrsort);
console.log(arrRepeat);
console.log(Array.from(new Set(arrRepeat)).sort((a, b) => a - b));
|