Complete the code to split the array into two halves.
const mid = Math.floor(arr.length [1] 2);
We divide the length by 2 to find the middle index.
Complete the code to recursively sort the left half of the array.
const left = divideAndConquer(arr.slice(0, [1]));
We slice from 0 to mid to get the left half.
Fix the error in the base case condition to stop recursion.
if (arr.length [1] 2) return arr;
The recursion stops when the array length is less than 2 (0 or 1).
Fill both blanks to merge two sorted arrays correctly.
while (i < left.length && j [1] right.length) { if (left[i] [2] right[j]) { result.push(left[i]); i++; } else { result.push(right[j]); j++; } }
The loop runs while both indexes are within their arrays. We compare left[i] > right[j] to decide which to push.
Fill all three blanks to complete the merge function return statement.
return result.concat(left.slice([1])).concat(right.slice([2])); // Variables used: i, j // [3] is the variable for the right array index
We slice the remaining elements from left starting at i and from right starting at j. The variable for right index is j.
