I haven’t run the code so just guessing (it would be helpful if you can provide the complete code with what array you are using etc so we can actually run it) - I see that in left
you include mid
. This is problematic if you think about inputting an array of 2 elements, both end up in left
and nothing in right
causing infinite recursion.
I think the guideline on this forum shows you some tips on debugging. In this case you can try to console.log(vals)
to see what’s actually happening and also use simple examples (what if the array length is only 1, what if 2,…) to narrow down the problem.