Lodash from scratch.
"Write your own _.get" is a staple of frontend interviews because small utilities show how you handle edge cases. Each question here rebuilds a Lodash-style function in plain JavaScript and is checked by tests: paths with arrays, holes, cycles, Dates and Maps, prototype pollution, and the exact order things run.
5 of these questions have free answers; the rest are in Pro. Updated .
26
questions
- Easy
- 14
- Medium
- 12
What interviewers look for
- You match the library's behaviour on edge cases: missing paths, array indexes in paths, holes, NaN and empty input.
- You handle object graphs safely: cycles, shared references, Dates, Maps and Sets, and keys like __proto__.
- You keep this, arguments and timing right in wrappers such as once, memoize, curry, debounce and throttle.
- You can say when a built-in (structuredClone, Object.groupBy, Array.prototype.flat) already does the job.
Easy14
- Implement a
once()function using closuresImplement once(fn). It returns a new function that calls fn the first time it is called and returns its result. Every… - Implement a function to flatten a nested arrayFreeImplement flatten(array, depth = Infinity). It returns a new array with nested arrays flattened into it, up to depth…
- Implement
groupBy()for an array of objectsImplement groupBy(items, iteratee). It returns an object whose keys are group names and whose values are arrays of the… - Implement
get(object, "a.with a default valueImplement get(object, path, defaultValue), like Lodash's _.get. It reads a nested value by path and returns defaultValue…b. c") - Implement
chunk(array, size)Implement chunk(array, size = 1), like Lodash's _.chunk. It splits the array into groups of size items. The last group… - Implement a basic
deepEqual()for nested arrays and objectsImplement deepEqual(a, b). It returns true when two values have the same structure and the same primitive values,… - Implement
set(object, "a.Implement set(object, path, value), like Lodash's _.set. It writes value at a nested path, creating any missing objects…b. c", value) - Implement
classNames()for conditional CSS classesReact components often build a className from conditions. Implement classNames(...args), which joins class names into… - Squash a nested object into dot-path keys, and unsquash it backForm libraries, query strings and analytics payloads often store nested data as flat "a.b.c" keys. Implement both…
- Implement a deep
omit()that removes keys at any depthBefore logging an API response or sending it to analytics, you want to strip fields such as password and token wherever… - Implement lodash-style array helpers:
compact,difference,intersection,fill,fromPairs,dropWhileandfindLastIndexSmall lodash helpers are a common warm-up: each one is a few lines, and the interviewer watches how you handle indices,… - Implement lodash-style number and object helpers:
clamp,mean,inRange,range,maxBy,minByandobjectMapThese helpers look trivial until the interviewer asks about the second argument being optional, a negative step or a… - Implement
countBy,unionByanddropRightWhileThree small collection helpers that show up in dashboards and data cleanup. Each one accepts an iteratee: either a… - Invert an object, collecting duplicate values into arraysInverting an object swaps keys and values: { en: "English", fr: "French" } becomes { English: "en", French: "fr" }. When…
Medium12
- Implement debounce() with
cancel()andflush()FreeImplement debounce(fn, wait). It returns a debounced function that delays calling fn until wait milliseconds have passed… - Implement
throttle()with leading and trailing optionsFreeImplement throttle(fn, wait, { leading = true, trailing = true } = {}). The throttled function calls fn at most once per… - Implement
curry()supporting partial applicationFreeImplement curry(fn). It returns a curried version of fn that keeps collecting arguments until it has at least fn.length… - Implement
compose()andpipe()Implement two helpers that chain functions: - Implement deep clone with circular references,
Map,Set, andDateImplement deepClone(value). It returns a copy where every nested object is new, so changing the copy never changes the… - Implement
memoize()with custom cache keysFreeImplement memoize(fn, resolver). It returns a function that caches the results of fn, so calling it again with the same… - Write a deep
mergethat is safe from prototype pollutionConfig loaders, query-string parsers and "settings" endpoints often deep-merge user-controlled JSON into an object. A… - Implement an immutability helper with
$set,$push,$mergeand$applyBefore Immer, React apps updated nested state with immutability-helper: a spec object that mirrors the shape of the data… - Implement
debounce()withleading,trailingandmaxWait, pluscancel(),flush()andpending()Question 26 builds a trailing-only debounce with cancel() and flush(). Real code needs the options Lodash offers: fire… - Implement
curry()with placeholders that later calls fill left to rightQuestion 28 builds curry(fn) that collects arguments in order. Lodash and Ramda also let you skip an argument with a… - Implement a complete
isEqual(): Dates, RegExps, Maps, Sets, typed arrays, prototypes and cyclesQuestion 18 compares nested arrays and plain objects. Real data also holds dates, regular expressions, Maps, Sets,… - Deep-filter a nested object by a predicate and drop empty branchesYou have a large settings or API object and want only the parts that match a rule, for example "only the numbers" or…
Practise with tests and full answers.
Every question has a runnable editor, tests and a step-by-step solution. Passes from ₹149, paid once; nothing renews.
Frequently asked
Which Lodash functions are asked most in interviews?
get and set with a path, chunk, groupBy, cloneDeep, isEqual, merge, flatten, once, memoize, curry, debounce and throttle. classNames, deep omit and squashing a nested object into dot paths come up often too.
Should I use Lodash or write these myself at work?
At work, prefer built-ins (structuredClone, Object.groupBy, optional chaining) and import single Lodash functions only when you need their edge-case handling. In an interview, writing them shows you know what those edge cases are.
How is this different from writing polyfills?
A polyfill recreates a standard built-in, such as Array.prototype.map, exactly as the specification defines it. A Lodash function is a library utility with its own documented behaviour, so the task is matching that behaviour and explaining your choices.