Composition & Monads — Series 2

Preview — 3 of 10 questions

javascript
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const double = x => x * 2;
const inc = x => x + 1;
const f = compose(double, inc);
console.log(f(5));
A11
B12
C6
D10

javascript
const curry = fn => (...args) =>
  args.length >= fn.length ? fn(...args) : (...more) => curry(fn)(...args, ...more);
const add3 = curry((a, b, c) => a + b + c);
console.log(add3(1)(2)(3), add3(1, 2)(3), add3(1, 2, 3));
A6 undefined 6
BNaN NaN 6
C6 6 6
D1 3 6

What's the key conceptual difference between currying and partial application?

APartial application only works with arrow functions; currying only works with regular function declarations
BThey are exactly the same technique, just named differently by different communities
CCurrying can only be applied to functions with exactly two parameters
DCurrying transforms a function into a chain of unary (single-argument) functions; partial application is the more general act of pre-filling any subset of arguments, which can still return a function that accepts several remaining arguments at once

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.