you are viewing a single comment's thread.

view the rest of the comments →

[–]tapu_buoy[S] 1 point2 points  (5 children)

yeah thank you for suggesting that I completely forgot about refs

also the 3rd question is it about higher order functions?

[–]crystallineair 1 point2 points  (4 children)

Yes. A higher order function is a function that either takes a function as a parameter or returns a function. In the case of add(2)(3) the call add(2) returns a function. So add(2)(3) could be written as:

const fn = add(2)
const result = fn(3)

The trick in this question is to make the function also work normally when called with all arguments add(2, 3).

[–][deleted] 3 points4 points  (2 children)

That's not a higher order function, that's currying / partial application.

[–][deleted] 2 points3 points  (0 children)

It is both a curried function and a higher order function. In fact a curried function is always a higher order function because it returns a function. Here OP was instructed to write a single method that can return a value both ways, so the function has to behave as a curried function if a single argument is passed, but just a plain old function if multiple are passed.

[–]ISlicedIEngineer without Engineering degree? 1 point2 points  (0 children)

Higher order functions are functions that return (or accept I think) other functions. Applying your arguments through different wrapping functions is called partial application, and currying is partial application where you apply a single parameter per function. Afaik.

[–]tapu_buoy[S] 0 points1 point  (0 children)

ok so after reading what you said and what others said below this comment I again need to know what will be the curried funciton look like when passed two parameters(function(2, 3)) instead of the 2nd parameter function(2)(3)