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.
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.
You do not need else, if you return in after your if statement.
Always use === for tests of equality in JavaScript.
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.
'Harder to read' is a very subjective category. I can't stand reading loops, because they don't tell me what the problem was. There is only the solution. With higher level methods there is a problem description there. If you throw in decent variable names, this is not more complicated to read (aka understand) than 'traditional' loops.
Only in computer science there is no debate about 0 being positive. If you consider a number n to be positive if and only if n > 0, then it makes perfect sense. You do not check for the 0 then. The array [0] then contains a negative element for each positive element.
I do have the same problem. Timeout after 10 seconds. Next thing I do: Generate a long list for 7 and 3, hardcode them in the solution and let's see what happens then.
There are already open issues about that, please don't open another.
This comment is hidden because it contains spoiler information about the solution
>>
operator has lower precedence than addition, but it's easier on an eye when the left side is inside the braces.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.
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.
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.
This is a baseless statement.
A couple of things.
'Harder to read' is a very subjective category. I can't stand reading loops, because they don't tell me what the problem was. There is only the solution. With higher level methods there is a problem description there. If you throw in decent variable names, this is not more complicated to read (aka understand) than 'traditional' loops.
I very much like the class and the way to calculate the weight. Kudos!
This comment is hidden because it contains spoiler information about the solution
Only in computer science there is no debate about 0 being positive. If you consider a number n to be positive if and only if n > 0, then it makes perfect sense. You do not check for the 0 then. The array [0] then contains a negative element for each positive element.
It should be "How did you find out...?" I did not found your secret...
I do have the same problem. Timeout after 10 seconds. Next thing I do: Generate a long list for 7 and 3, hardcode them in the solution and let's see what happens then.
Thanks for the heads up.
This comment is hidden because it contains spoiler information about the solution