Ad
  • Custom User Avatar

    >> operator has lower precedence than addition, but it's easier on an eye when the left side is inside the braces.

  • Custom User Avatar

    I think you are confusing the concepts of 'recursion' and 'functional programming'. Not creating side effects is the point of FP, and FP happens to use recursion. But recursion itself is simply the concept of a function calling itself, which does not at all limit it to FP.

  • Custom User Avatar

    No it's not. You are working with recursion on a global variable. This goes against the basic idea of functional and recursive programming. The idea is to work with values and not with global objects and create side effects.

  • Custom User Avatar

    I would definetly check ... if only the reference is pushed to the stack

    Objects are always passed by reference. This code wouldn't even work otherwise, since you'd run out of stack space immediately for huge inputs.

    it is generally not the idea of recursion to work with reference objects

    This is a baseless statement.

  • Custom User Avatar

    A couple of things.

    1. You do not need else, if you return in after your if statement.
    2. Always use === for tests of equality in JavaScript.
    3. You can do that in a recursive way. The bigger the array, the bigger the call stack gets. I would definetly check what happens to the array and if only the reference is pushed to the stack, but it is generally not the idea of recursion to work with reference objects.