With recursive functions, it means that returning the console will be useless because it is different from the usual loop, it must end the last position of the recursive tree before returning all the values ββin the console, so if you add one of the positions of the array with a deeper position like [[[[3]]]], it will move to the end of the position and then return all the values, so if you place some console to see how your recursive function works, you will get some kind of tree, and not like a regular cycle that is dangerous with recursive functions, and they can be quite hard for memory, talking about CPU usage on a production server. therefore, if you can perform this operation using any recursive function, it will be better.
So if you change the code to
steamroller([1, [2],[3, [4]]]);
Speaking of levels in a recursive tree, therefore, if you put [[3]] as [[4]], the return will be at the same level of the tree.
steamroller([1, [2],[[3], [4]]]);
Hi, I hope you can better understand recursive functions.
source share