Command Palette

Search for a command to run...

Hectal
Phase 15: Patterns, Security and Interviews
JavaScript · Exercise 1 of 6Next
Intermediate

Your functional toolkit: pipe, curry and memoize

Write three small helpers from Topics 15.1 and 15.3, then use them.

1. pipe(...fns) returns a function that passes a value through every function left to right. With no functions, it returns the value unchanged.

2. multiply is curried: multiply(3)(4) returns 12.

3. toSlug must be built with pipe from the given trim, lower and dashes, so toSlug(" Hello Big World ") returns "hello-big-world".

4. memoize(fn) returns a function that caches results by all its arguments (use JSON.stringify(args) as the key). It must call fn only once per different set of arguments, even when the result is undefined.

What Check tests

  1. pipe runs functions left to right
  2. pipe() with no functions returns the value unchanged
  3. multiply(3)(4) is 12
  4. toSlug gives hello-big-world and is built with pipe
  5. memoize calls the function once per argument list
  6. memoize also caches undefined results
  7. No errors

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.