I thought I had figured this one out- then I forgot I changed the test case to not have dupe values… then it ‘passed’ locally- but not on FCC… sorry for the confusion. Let’s see if I can refactor below to get to work for arrays with dupe values now.
let swap = (arr,a,b) => ([arr[a],arr[b]] = [arr[b],arr[a]]);
let partition = (arr, left, right, pivot) => {
while(left < right){
while(arr[left] < arr[pivot]){
left++;
}
while(arr[right] > arr[pivot]){
right--;
}
if (left < right){
swap(arr,left,right);
left++;
right--;
}
}
return left;
}
let quickSort = (array, left = 0, right = array.length-1) => {
if(left < right){
let pivot = left;
let partitionIndex = partition(array,left,right,pivot);
quickSort(array, left, partitionIndex);
quickSort(array, partitionIndex+1, right);
}
return array;
}
// test array:
console.log(quickSort([1, 4, 2, 8, 345, 1123, 431, 32, 5643, 63, 123, 43, 22, 55, 11, 234, 92]));