🧮 JavaScript

Currying and Function Composition — FP Interview Favourites

📅 Jul 4, 2026 ⏱ 3 min read

Product-company interviews probe functional concepts. Four ideas cover the questions.

Pure functions

Same inputs → same output, no side effects. Pure functions are trivially testable and cacheable — say this and you've answered "why FP?"

Currying — one argument at a time

const multiply = (a) => (b) => a * b;
const double = multiply(2);      // partially applied!
const gst = multiply(1.18);

double(50);   // 100
gst(1000);    // 1180

// real use: configured helpers
const withAuth = (token) => (url) => fetch(url, { headers: { Authorization: token } });
const api = withAuth(userToken);
api("/students"); api("/marks");

Composition — pipelines of small functions

const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);

const clean = pipe(
  (s) => s.trim(),
  (s) => s.toLowerCase(),
  (s) => s.replace(/\s+/g, "-")
);
clean("  Hello World  ");   // "hello-world"

The interview classic: memoize

function memoize(fn) {
  const cache = new Map();
  return (...args) => {
    const key = JSON.stringify(args);
    if (!cache.has(key)) cache.set(key, fn(...args));
    return cache.get(key);
  };
}

Closure + higher-order function + caching in ten lines — three topics, one answer.

← All Articles