Function Currying in JavaScript Recursively
What is function currying?
Function currying is a process in functional programming in which a function with multiple arguments can be transformed into a sequence of nesting functions.
Example of function currying:
The following is the code example of function currying:
const mul = (x) => { return (y) => x * y; } console.log(mul(2)(3));
Most common and tricky interview question about function curry
Write a function that uses function currying to display the following output:
mul(2)(3)(5)(4)()
Output: 120
The problem solution:
const mul = (x) => { return (y) => { if (y) { return mul(x * y); } else { return x; } } }; console.log(mul(5)(3)(2)(4)()) // 120