Hi! I’ve implemented quickSort, I know that implementation is not very elegant, but here it is:
function quickSort(array) {
if(array.length <= 1){
return array;
}
let pivotValue = array[0];
let lessValues = [];
let greaterValues = [];
for(let i=1;i<array.length;i++){
if(pivotValue < array[i]){
greaterValues.push(array[i]);
}else{
lessValues.push(array[i]);
}
}
var sortedLow = quickSort(lessValues);
var sortedHigh = quickSort(greaterValues);
//console.log(sortedLow, pivotValue, sortedHigh)
sortedLow.push(pivotValue);
var result = sortedLow.concat(sortedHigh);
return result;
}
And there is what I see in the console when I run the tests:
quickSort should not use the built-in .sort() method.
/