Tell us what’s happening:
This part doesn passed " quickSort
should return an array that is unchanged except for order." when i tested the code on the chrome console. it works exactly as expect, I am comfusing.
Your code so far
function quickSort(array) {
if(array.length<2) return array;
const basic = array[0],left=[],right=[];
for(let i=1;i<array.length;i++){
const iv = array[i];
iv > basic && right.push(iv);
iv < basic && left.push(iv);
}
return quickSort(left).concat(basic,quickSort(right));
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
.
Challenge: Implement Quick Sort
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/implement-quick-sort#