JS Built-ins
FunctionalProgrammingbeginner

Basic currying β€” manual

πŸ“– Usage Example
const add = a => b => a + b;
add(2)(3); // 5

Currying converts a multi-argument function into a chain of single-argument functions.

Currying Basics

Currying is a technique of translating a function that takes multiple arguments into a sequence of functions that each take a single argument.

Challenge: Create a curried add function using arrow functions. Instead of add(a, b), it should be called as add(a)(b).

πŸ’‘ Hints (3)
  • β€’ Use arrow functions for concise syntax
  • β€’ Return a function that takes b from the outer function
  • β€’ Each level of nesting handles one parameter