Ad
  • Custom User Avatar

    Array(n) creates an array of length n, [...Array(n)] creates an array filled with undefined, of length n.

  • Custom User Avatar

    Can you explain how you brought an array into the function without 'let arr = []'?

  • Custom User Avatar

    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 ).

    But that's not the point here.

  • Custom User Avatar

    I suspect, this one will fail when your n is large enough.