I fail to pass the third challenge :
" quickSort
should return an array that is unchanged except for order."
in console my result looks as intended
Your code so far
function quickSort(array) {
let l = array.length
if (l > 1) {
let pivot = array[Math.floor(l/2)]
let small = []
let large = []
for (let i=1; i<l; i++) {
if (array[i] <= pivot) {
small.push(array[i])
} else {
large.push(array[i])
}
};
// console.log(small, large, pivot)
return quickSort(small).concat(pivot, quickSort(large))
} else return array;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
console.log(quickSort([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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
.
Challenge: Implement Quick Sort
Link to the challenge: