A bit late to the party but here is my take. I'm basically substituting cond ? valueWhenTrue : valueWhenFalse for a logical equivalent (cond && valueWhenTrue) || valueWhenFalse + calling the function recursively.
Note: array returned is in reverse order ! But we can easily solve that with .reverse()
A bit late to the party but here is my take. I'm basically substituting
cond ? valueWhenTrue : valueWhenFalse
for a logical equivalent(cond && valueWhenTrue) || valueWhenFalse
+ calling the function recursively.Note: array returned is in reverse order ! But we can easily solve that with
.reverse()