Tell us what’s happening:
Describe your issue in detail here.
I’m having a hard time figuring out how to implement the mergeSort algorithm.
Following the challenge suggestions, I just got the merge function (for merging two sorted arrays) working, I think, but there are a couple of points about the mergeSort function that is unclear to me.
- Why split the initial array into halves?
If we need single item arrays, why bother? Couldn’t we just iterate over the initial array and create an array for every element? - Aren’t we trying to obtain something like:
mergedArr = [[4], [22], [13], [2], [10] ]to feed ourmergefunction?
The only way I can think of for returning all the halves at once is creating an array of single item arrays. Is this correct?
As I don’t want to look at the solutions just yet I was hoping someone could push me in the right direction.
Thank you!
Challenge: Implement Merge Sort
Link to the challenge: