Dealing with many parameters

The idea of currying, by itself, is simple. If you need a function with, say, three parameters, you could write something like the following by using arrow functions:

const make3 = (a, b, c) => String(100 * a + 10 * b + c);

Alternatively, you can have a sequence of functions, each with a single parameter, as shown here:

const make3curried = a => b => c => String(100 * a + 10 * b + c);

Alternatively, you might want to consider them as nested functions, like the following code snippet:

const make3curried2 = function(a) {  return function(b) {    return function(c) {      return String(100 * a + 10 * b + c);    };  };};

In terms of usage, there's an important difference in how you'd use each function. While you would call the ...

Get Mastering JavaScript Functional Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.