Higher-Order Functions
higher-order-functions
Code Snippets
Memoize Higher-Order Function
Memoization caches function results keyed by arguments so repeat calls return in O(1). This snippet covers the canonical single-arg memoize, a multi-arg version that handles object identity via a `Map` chain, and an LRU-bounded variant that prevents unbounded cache growth. Use it for pure functions whose work dwarfs the lookup cost (parsing, layout calc, recursive DP).
Generate Arrays from Args, Random, and Higher-Order Inputs
Three array-generation idioms that come up constantly: building a fixed-length array of computed values (random fillers, ranges, defaults), turning function arguments into an array, and writing higher-order functions that return array transformers parameterized by a constant. Each is one line of code, but the patterns generalize to test fixtures, configuration, and small DSLs.
Question Banks
Currying and Functional Composition Quiz
Compose, curry, memoize, and partially apply: the higher-order toolkit that turns small JavaScript functions into reusable building blocks.
JavaScript Add-N via Currying: Two Approaches Quiz
Two seeded ways to build an `adder(n)` that adds `n` to its argument (closure-returning-function and `Function.prototype.bind`), plus two companions on three-arg currying and a generic curry helper.
Community
The HOC + Render Props Patterns I Still Read in Legacy Repos
Hooks made HOCs and render props optional, but pre-2019 codebases still ship them. Four patterns to recognize when you inherit a Redux-era React app.
Mastering Closures in JavaScript
What a closure actually captures (variable bindings, not values), why the loop-with-var bug exists, and the real-world patterns that lean on closures: module pattern, currying, and React useCallback.
Debounce, Throttle, and the Difference People Miss
Debounce settles, throttle paces. The visual difference, the canonical implementations of both (with leading-edge and trailing-call variants), and the three edge cases that bite hand-rolled wrappers.
