 # Return statement recursive function

Tell us what’s happening:

I’m having trouble with my return statement on my quick sort. I’m trying to break down an array into sub arrays with all elements to the left being greater than the element at a random index and all the elements to the right being greater than the value at the random index and keep returning this over and over until there is nothing left.

``````if(rightArray.length > 0 && leftArray.length > 0){
return quickSort(rightArray) && quickSort(leftArray)
}
``````

This bit of code only returns whatever I put first. How do I make it return the quickSort function for both subarrays?

``````
function quickSort(array) {
// change code below this line
let myInt = Math.floor(Math.random()* array.length)
let leftArray = [];
let rightArray = [];
for(let i =0; i<array.length; i++){
if(array[i] < array[myInt]){
leftArray.push(array[i])
}
if(array[i] > array[myInt]){
rightArray.push(array[i])
}
}

if(leftArray.length > 0){console.log(leftArray)}
if(rightArray.length > 0){console.log(rightArray)}

console.log(myInt)
if(rightArray.length > 0 && leftArray.length > 0){
return quickSort(rightArray) && quickSort(leftArray)
}
if(leftArray.length > 0 && rightArray.length == 0){
return quickSort(leftArray)
}
if(rightArray.length>0 && leftArray.length ==0){
return quickSort(rightArray)}
}

// change code above this line

//console.log(Math.floor(Math.random()* 2));
//console.log(Math.random()* 5)
// test array:
quickSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36`.

Challenge: Implement Quick Sort

``````function testThis() {