I am taking the Udemy Course of algorithms and data structures. The goal is to write a function that will flatten an array. For example if the argument passed in is
flatten([1, [2, [3, 4], [[5]]]])
the function should return
[1, 2, 3, 4, 5]
My function does not seem to account for the deeply nested 5 on the last index of the array. I’m not sure why it doesn’t .
the reason it is skipping the 5 is because your only sending arr[0] back into the function so when it becomes this [ [ 3, 4 ], [ [ 5 ] ] ] its only sending [3, 4] back in and [ [ 5 ] ] is lost