let testArr = [5, 17, 1, 33, 6, 20];
document.write(`Original Array is [${testArr}]<br/>`);
function quickSort(arr) {
if (arr.length < 2) {
return arr;
}
else {
let baseElem = arr[Math.floor(arr.length/2)];
let smallElem = arr.slice(1).filter(elm => elm < baseElem);
let bigElem = arr.slice(1).filter(elm => elm >= baseElem);
let result = [quickSort(smallElem).concat(baseElem).concat(quickSort(bigElem))];
return result;
}
}
let resultArr = quickSort(testArr);
document.write(`Ordered Array is[${resultArr}]`);
console