Search⌘ K
AI Features

Solution Review: Partial Functions

Explore the concepts of partial functions and currying in JavaScript by reviewing example solutions. Understand how to transform functions to take fewer arguments using currying and function binding. This lesson helps you grasp key functional programming techniques often asked in coding interviews.

Question 1: Solution review

In the previous lesson, you were given the following code:

Javascript (babel-node)
function func1(f) {
return function(x) {
return function(y) {
return f(x, y);
}
}
}
func1(addition)(2)(3)

For the code above, you had to answer the following question:

Explanation

The correct option is B. func1 is a curry function. Let’s understand why.

Currying converts a function taking n arguments into chains of n function calls. It always returns a function that takes one argument, and we keep calling this function until all the arguments have been applied. ...