It will, for n over ~8000, or maybe ~16000. JS has a rather small stack.
ETA: n > 11387 for Node 8.x, actually ( Node 6.x does slightly better ). Oh, BTW, factorial(n) goes to Infinity for n > 170. ( I haven't bothered to figure out when it starts losing precision. Node 10.x has BigInt for that. )
Trampolining it would solve that ( or some clever compiling with continuation passing and tail recursion optimisation ).
Array(n)
creates an array of lengthn
,[...Array(n)]
creates an array filled withundefined
, of lengthn
.Can you explain how you brought an array into the function without 'let arr = []'?
It will, for
n
over~8000
, or maybe~16000
. JS has a rather small stack.ETA:
n > 11387
for Node 8.x, actually ( Node 6.x does slightly better ). Oh, BTW,factorial(n)
goes toInfinity
forn > 170
. ( I haven't bothered to figure out when it starts losing precision. Node 10.x hasBigInt
for that. )Trampolining it would solve that ( or some clever compiling with continuation passing and tail recursion optimisation ).
But that's not the point here.
I suspect, this one will fail when your n is large enough.