Ive worked on this challenge a few times, with different strategies like recursive (still dont understand it)
and today i used .flat() which doesnt really work … for example .flat(Infinity);
FYI - We are in the process of changing this challenge to no longer allowing the flat method in the solution, since it defeats to purpose of solving the challenge with an algorithm.
This is one of those classic recursive algorithms every programmer should know, so restricting .flat() makes total sense. I would really suggest to try to solve it recursively, it’s quite far from “hell”.
flatMap() should be restricted not only from the challenge but also from existence
It kinda reminds about the times when JS was like this: "hello, world".blink(). If .reduce(), .filter() and other HOF methods where people they would definitely come to Ecma office with “WFT” faces…
First step to understand recursion is to understand precedence. Function call has very high precedence, it means that result of the function will be calculated before almost anything else. So, when you have something like this in your code:
return func();
JS will first compute result of the func() and then return it.