Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.