Currying Function in JavaScript
Level 4213 keystrokes
Currying transforms a function with multiple arguments into a sequence of single-argument functions.
JavaScript code
// Curry helper: takes a 2-arg function and returns nested functions1const curry = (fn) => (a) => (b) => fn(a, b);// Simple add function that takes two arguments2const add = (a, b) => a + b;// Create curried version of add3const curriedAdd = curry(add);// Call with both arguments: 5 + 3 = 84console.log(curriedAdd(5)(3));// Partial application: create add10 by fixing first arg to 105const add10 = curriedAdd(10);// 10 + 5 = 156console.log(add10(5));// 10 + 20 = 307console.log(add10(20));Output
8 15 30
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
(× 14)× 14=× 8;× 7>× 4.× 3,× 2+× 1