Merge sort implementation using divide-and-conquer
To expand on CiaPan's answer. Your solution might look like:

result = mergeAndSort([8,4,17,2,1,32]);


You would write code that would do:

let a = mergeAndSort([8,4,17]);
let b = mergeAndSort([2,1,32]);
return merge(a, b);


This would be recursive, so mergeAndSort([8,4,17]) would do:

let a = mergeAndSort([8,4]);
let b = mergeAndSort([17]);
return merge(a, b);


Now mergeAndSort would be called with [8,4] which would be:

let a = mergeAndSort([8]);
let b = mergeAndSort([4]);
return merge(a, b);


Now lastly you have mergeAndSort([8]) which is trivially implemented as

return [8]


Or alternatively, in pseudocode:

function mergeAndSort(array) {
  if (array.length &lt;= 1)
    return array;
  let a = mergeAndSort( leftHalfOfArray(array)  );
  let a = mergeAndSort( rightHalfOfArray(array) );
  return merge(a,b); 
}