Polyfill interview questions
Practice 46 questions on polyfill. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
46 questions
- EASY
Array findLast / findLastIndex
Implement findLast and findLastIndex — scan an array from the end for the last element matching a predicate.
15 minJavaScript - EASY
Array.prototype.at
Implement Array.prototype.myAt — return the element at a given index, supporting negative offsets from the end.
15 minJavaScript - EASY
Array.prototype.every
Implement Array.prototype.every — return false as soon as an element fails the predicate, true when empty.
15 minJavaScript - EASY
Array.prototype.filter
Implement Array.prototype.filter from scratch as a method on the array prototype.
15 minJavaScript - EASY
Array.prototype.flat
Implement Array.prototype.flat — flatten nested arrays to a given depth (default 1, Infinity for all levels), dropping holes.
15 minJavaScript - EASY
Array.prototype.forEach
Implement Array.prototype.forEach — run a callback on each element as (value, index, array), skipping sparse holes.
15 minJavaScript - EASY
Array.prototype.includes
Implement Array.prototype.includes — test membership with SameValueZero so NaN matches, honoring negative fromIndex.
15 minJavaScript - EASY
Array.prototype.indexOf
Implement Array.prototype.indexOf — first index of a value by strict equality, supporting a negative fromIndex.
15 minJavaScript - EASY
Array.prototype.some
Implement Array.prototype.some — return true as soon as any element passes the predicate, false when empty.
15 minJavaScript - EASY
Map.groupBy
Implement Map.groupBy — group an iterable into a Map whose keys can be any value, preserving key insertion order.
15 minJavaScript - EASY
Object.entries
Implement Object.entries — return an object's own enumerable string-keyed [key, value] pairs in insertion order.
15 minJavaScript - EASY
Object.fromEntries
Implement Object.fromEntries — build an object from any iterable of [key, value] pairs, with later keys winning.
15 minJavaScript - EASY
Object.is
Implement Object.is — same-value equality that treats NaN as equal to itself and keeps +0 distinct from -0.
15 minJavaScript - EASY
Promise.race
Implement Promise.race so it settles with the outcome of whichever input promise settles first.
15 minJavaScript - EASY
Promise.reject
Implement a function that returns a Promise already rejected with the given reason.
15 minJavaScript - EASY
String.prototype.padStart
Implement String.prototype.padStart — pad a string to a target length on the left, truncating a multi-char pad.
15 minJavaScript - EASY
String.prototype.repeat
Implement String.prototype.repeat — join a string n times, throwing RangeError on a negative or infinite count.
15 minJavaScript - EASY
String.prototype.trim
Implement String.prototype.trim — strip leading and trailing whitespace, including Unicode whitespace, from a string.
15 minJavaScript - MEDIUM
Array.fromAsync
Implement Array.fromAsync: build a promise of an array from a sync or async iterable, awaiting each value in order.
30 minJavaScript - MEDIUM
Array.prototype.concat
Implement Array.prototype.myConcat — merge arrays and values into a new array, spreading nested arrays one level deep.
25 minJavaScript - MEDIUM
Array.prototype.find
Implement Array.prototype.find and findLast — return the first or last element matching a predicate, or undefined.
25 minJavaScript - MEDIUM
Array.prototype.flatMap
Implement Array.prototype.flatMap — map each element, then flatten the mapped results by one level.
25 minJavaScript - MEDIUM
Array.prototype.map
PREMIUMImplement Array.prototype.myMap — return a new array with the callback applied to each element, skipping holes.
25 minJavaScript - MEDIUM
Array.prototype.reduce
PREMIUMImplement Array.prototype.myReduce — fold an array down to one value, handling sparse arrays and missing initial values.
25 minJavaScript - MEDIUM
Array.prototype.reduceRight
Implement Array.prototype.reduceRight — fold an array right-to-left, throwing on an empty array with no initial value.
25 minJavaScript - MEDIUM
Array.prototype.splice
Implement Array.prototype.splice — remove and insert elements in place, returning the removed ones, with clamped indices.
25 minJavaScript - MEDIUM
Base64 atob / btoa
Implement base64 encoding and decoding from scratch — pack bytes into 6-bit groups, map to the alphabet, and handle padding.
35 minJavaScript - MEDIUM
Deep Freeze
Recursively freeze an object and every nested object and array, making the whole structure deeply immutable.
25 minJavaScript - MEDIUM
ES5 Class Inheritance
Wire up classical inheritance the pre-class way — link prototypes with Object.create, restore the constructor, and call the superclass constructor.
30 minJavaScript - MEDIUM
Function.prototype.apply
Implement Function.prototype.myApply — invoke the function with a given `this` and an array of arguments.
25 minJavaScript - MEDIUM
Function.prototype.bind
PREMIUMImplement Function.prototype.myBind — return a new function with a fixed `this` and optional preset arguments.
25 minJavaScript - MEDIUM
Function.prototype.call
Implement Function.prototype.myCall — invoke the function with a given `this` and a list of arguments.
25 minJavaScript - MEDIUM
getElementsByClassName
Implement a function that returns all DOM elements containing every one of the specified class names.
25 minJavaScript - MEDIUM
Immutable Array Methods
Implement the ES2023 change-by-copy trio — toSorted, toReversed, and with — that copy an array instead of mutating it.
30 minJavaScript - MEDIUM
Iterator Helpers
Build lazy, chainable iterator helpers — map, filter, take, drop, and flatMap — that pull one value at a time.
35 minJavaScript - MEDIUM
JSON.stringify
PREMIUMImplement a function that converts a JavaScript value into its JSON string representation.
25 minJavaScript - MEDIUM
Object.assign
Implement Object.assign — copy own enumerable string and symbol properties from sources onto a target, skipping nullish.
25 minJavaScript - MEDIUM
Promise.all
Implement Promise.all so it resolves with an array of results or rejects on the first rejection.
25 minJavaScript - MEDIUM
Promise.allSettled
PREMIUMImplement Promise.allSettled from scratch, resolving to an array of fulfilled or rejected outcomes for each input.
25 minJavaScript - MEDIUM
Promise.any
PREMIUMImplement Promise.any so it resolves with the first fulfilled value or rejects with an AggregateError.
25 minJavaScript - MEDIUM
Promise.resolve
Implement Promise.resolve — wrap a value in a fulfilled promise, returning thenables unchanged and adopting their state.
25 minJavaScript - MEDIUM
Promise.withResolvers
Implement Promise.withResolvers — return a new promise alongside its external resolve and reject functions.
25 minJavaScript - MEDIUM
String replaceAll / matchAll
Implement replaceAll and matchAll — replace every occurrence of a substring or global pattern, and iterate every match with its capture groups.
35 minJavaScript - MEDIUM
String to Number (parseInt)
Reimplement JavaScript's parseInt — skip leading whitespace, read an optional sign and radix prefix, consume valid digits for the base, and stop at the first invalid character.
25 minJavaScript - MEDIUM
The new Operator
PREMIUMImplement newOperator — reproduce the four steps the new keyword performs, honoring the object-return override.
30 minJavaScript - HARD
JSON.stringify II
PREMIUMImplement JSON.stringify with full spec support including replacer, indentation, and circular reference detection.
40 minJavaScript