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.