All quizzesHard
Composition & Monads — Series 3
Preview — 3 of 10 questions
What is logged?
javascript
const pipe = (...fns) => (x) => fns.reduce((acc, f) => f(acc), x);
const trim = (s) => s.trim();
const words = (s) => s.split(/\s+/);
const count = (a) => a.length;
console.log(pipe(trim, words, count)(' hello brave new world '));A6
B1
C4
D24
What is logged?
javascript
const _ = Symbol('_');
const partial = (fn, ...preset) => (...later) => {
const args = preset.map((p) => (p === _ ? later.shift() : p));
return fn(...args, ...later);
};
const greet = (greeting, name, punct) => `${greeting}, ${name}${punct}`;
const hi = partial(greet, 'Hi', _, '!');
console.log(hi('Ada'));AHi, Ada!
BHi, !Ada
CHi, Symbol(_)!
DAda, Hi!
Which statement distinguishes them correctly?
AThey are two names for the same transformation.
BCurrying fixes some arguments and returns a function of the rest; partial application splits a function into a chain of single-argument functions.
CPartial application only works on pure functions; currying works on any function.
DCurrying transforms an n-argument function into a chain of single-argument functions; partial application fixes some arguments now and returns a function taking the remainder.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.