Lead Frontend
​
​
Log inSign up
© 2026 Lead Frontend. Free educational content, provided as is; it may contain errors. Not affiliated with any company or product named on this site.
TermsPrivacyDisclaimerCopyrightLicenses & credits

JavaScript Functions

Implement utility functions, polyfills and async helpers in JavaScript.

Progress

0 / 119 completed

​
​
​
Difficulty
​
Topic
​
Company
​
Status
Recommended
Sort

Showing 119 questions

Array.prototype.at

Implement Array.prototype.at, including negative indices and the spec's integer coercion rules.

JS Functions
Easy
10 min

Array.prototype.concat

Implement Array.prototype.concat, including sparse arrays and Symbol.isConcatSpreadable.

JS Functions
Easy
15 min

Array.prototype.filter

Implement Array.prototype.filter with thisArg support and correct handling of sparse arrays.

JS Functions
Easy
10 min

Array.prototype.flat

Implement Array.prototype.flat with a depth argument, hole removal and an iterative variant.

JS Functions
Medium
15 min

Array.prototype.map

Implement Array.prototype.map, keeping holes in sparse arrays and supporting thisArg.

JS Functions
Easy
10 min

Array.prototype.reduce

Implement Array.prototype.reduce, including the no-initial-value rules and sparse arrays.

JS Functions
Easy
15 min

Array.prototype.square

Add a square() method to every array that returns a new array of squared values.

JS Functions
Easy
5 min

Async Queue with Priority

Run async tasks with a concurrency limit, starting higher-priority tasks first and keeping FIFO order within a priority.

JS Functions
Hard
35 min

Backbone Model

Build an observable Model class with defaults, get/set/unset, per-attribute change events, previous values and silent updates.

JS Functions
Hard
40 min

Cache Async (Deduplicate Requests)

Memoize an async function so concurrent calls share one in-flight promise, results expire after a TTL and failures are not cached.

JS Functions
Medium
25 min

Camel Case Keys

Deeply convert snake_case object keys from an API response into camelCase.

JS Functions
Medium
20 min

Cancellable Interval

Wrap setInterval so it returns a cancel function that stops future ticks.

JS Functions
Easy
5 min

Cancellable Timeout

Wrap setTimeout so it returns a cancel function instead of a timer id.

JS Functions
Easy
5 min

Chunk

Split an array into consecutive groups of a fixed size, with a shorter final group if needed.

JS Functions
Easy
10 min

Clamp

Restrict a number to an inclusive range between a lower and an upper bound.

JS Functions
Easy
5 min

classnames

Build a CSS class string from strings, numbers, nested arrays and conditional objects.

JS Functions
Medium
20 min

Compact

Return a new array with every falsy value removed.

JS Functions
Easy
5 min

Compose

Combine functions right to left into a single function, where each output feeds the next input.

JS Functions
Easy
10 min

Count By

Count how many elements of an array map to each key produced by an iteratee.

JS Functions
Easy
10 min

Curry

Turn a function of n arguments into one that can be called with those arguments one or several at a time.

JS Functions
Medium
20 min

Curry II (with placeholders)

Curry a function so that arguments can be supplied in any order using a placeholder value.

JS Functions
Hard
30 min

Data Merging

Merge workout session records by user: sum durations and combine equipment lists without duplicates.

JS Functions
Medium
20 min

Data Selection

Implement a small query function over an array of records: filtering, multi-key stable sorting, pagination and field projection.

JS Functions
Medium
30 min

Debounce

Delay invoking a function until a burst of calls has stopped for a given wait time.

JS Functions
Medium
20 min

Debounce II

Debounce with leading, trailing and maxWait options, plus cancel and flush.

JS Functions
Hard
35 min

Deep Clone

Make a deep copy of a JSON-like value so that no nested object or array is shared with the original.

JS Functions
Medium
15 min

Deep Clone II

Deep clone values with circular references, shared references, Date, RegExp, Map, Set, symbols and prototypes.

JS Functions
Hard
35 min

Deep Equal

Decide whether two JSON-like values are structurally equal, comparing nested objects and arrays by content.

JS Functions
Medium
20 min

Deep Map

Transform every leaf value in a nested object/array structure while preserving its shape.

JS Functions
Medium
20 min

Deep Merge

Recursively merge configuration objects without mutating the inputs, with clear rules for arrays and undefined.

JS Functions
Medium
25 min

Deep Omit

Remove the given keys from an object at every level of nesting, including inside arrays.

JS Functions
Medium
20 min

Dependency Injection Container

Build an IoC container with transient, singleton and scoped lifetimes, child scopes, overrides and circular-dependency detection.

JS Functions
Medium
35 min

Difference

Return the elements of an array that do not appear in any of the other given arrays.

JS Functions
Easy
10 min

Identical DOM Trees

Decide whether two DOM nodes are structurally identical: same tags, attributes, text and children, without using isEqualNode.

JS Functions
Medium
20 min

Drop Right While

Drop trailing elements of an array for as long as a predicate holds, scanning from the end.

JS Functions
Easy
10 min

Drop While

Drop leading elements of an array for as long as a predicate holds, then keep the rest.

JS Functions
Easy
10 min

Event Emitter

Implement an EventEmitter class with on, off and emit, the observer pattern behind Node's events module and DOM events.

JS Functions
Medium
20 min

Event Emitter II

Extend an event emitter with once, unsubscribe handles, bulk off and listener counts, with well-defined behaviour during emit.

JS Functions
Medium
25 min

Feature Flag Evaluator

Evaluate feature flags with a kill switch, targeting rules and a percentage rollout that uses stable hashing so users keep their bucket.

JS Functions
Medium
30 min

Fill

Overwrite a range of an array with a value, supporting negative start and end indices.

JS Functions
Easy
10 min

Find Index

Return the index of the first element that satisfies a predicate, starting from an optional index.

JS Functions
Easy
10 min

Find Last Index

Return the index of the last element that satisfies a predicate, searching backwards from an optional index.

JS Functions
Easy
10 min

Flatten

Flatten a nested array to a given depth, recursively or with an explicit stack.

JS Functions
Medium
20 min

From Pairs

Build an object from an array of [key, value] pairs, the inverse of Object.entries.

JS Functions
Easy
5 min

Function.prototype.apply

Implement Function.prototype.apply, including array-like argument lists and argument validation.

JS Functions
Medium
15 min

Function.prototype.bind

Implement Function.prototype.bind with partial application and correct behaviour under new.

JS Functions
Medium
20 min

Function.prototype.call

Implement Function.prototype.call without using call, apply or bind.

JS Functions
Medium
15 min

Get

Safely read a nested value from an object by a dot/bracket path, falling back to a default.

JS Functions
Medium
20 min

getElementsByClassName

Find every descendant element that has all of the given class names by walking the DOM tree yourself.

JS Functions
Medium
15 min

getElementsByStyle

Find descendant elements whose computed value for a CSS property equals a given value, normalising values like red vs #f00.

JS Functions
Medium
20 min

getElementsByTagName

Return every descendant element with a given tag name (or all of them for "*") by traversing the DOM tree.

JS Functions
Medium
15 min

Group By

Group the elements of an array into arrays keyed by the result of an iteratee.

JS Functions
Medium
15 min

Has

Check whether an object has an own property at a nested path, even when the value is undefined.

JS Functions
Medium
15 min

HTML Serializer

Turn a plain-object element tree into pretty-printed, correctly escaped HTML with indentation and void elements.

JS Functions
Easy
20 min

In Range

Check whether a number lies in a half-open range, with an optional start and swapped bounds.

JS Functions
Easy
10 min

instanceof

Re-implement the instanceof operator by walking the prototype chain.

JS Functions
Medium
15 min

Intersection

Return the unique values that appear in every one of the given arrays.

JS Functions
Medium
15 min

Is Empty

Decide whether a value is empty: no length, no size, or no own enumerable keys depending on its type.

JS Functions
Medium
15 min

jQuery Class Manipulation

Build a tiny $ wrapper with chainable addClass, removeClass, toggleClass and hasClass that work on every matched element.

JS Functions
Easy
15 min

jQuery CSS

Implement a $(selector).css() getter/setter that handles camelCase names, objects, automatic px units and removal.

JS Functions
Easy
15 min

JSON.parse (Lite)

Write a recursive-descent parser for JSON text that matches JSON.parse and throws SyntaxError on invalid input.

JS Functions
Hard
45 min

JSON.stringify

Reimplement JSON.stringify: escaping, undefined and function handling, toJSON, wrapper objects, cycles and BigInt errors.

JS Functions
Hard
40 min

List Format

Format a list of names into a readable sentence with options for sorting, de-duplication and an "and N others" cutoff.

JS Functions
Medium
20 min

LRU Cache

Implement a fixed-capacity cache that evicts the least recently used entry, with O(1) get and set.

JS Functions
Medium
25 min

Make Counter

Use a closure to build independent counters that remember their own state between calls.

JS Functions
Easy
10 min

Map Async

Map over a list with an async callback, running every call in parallel and keeping the results in input order.

JS Functions
Medium
15 min

Map Async with Limit

Map over a list with an async callback while never running more than a given number of calls at once.

JS Functions
Hard
30 min

Max By

Return the element whose iteratee value is largest, skipping elements that produce no comparable value.

JS Functions
Easy
10 min

Mean

Compute the arithmetic mean of an array of numbers, returning NaN for an empty array.

JS Functions
Easy
5 min

Memoize

Cache a function's results by argument so repeated calls with the same input skip the work.

JS Functions
Medium
15 min

Memoize II (multiple arguments)

Memoize a function of any number of arguments with a collision-free cache keyed on every argument.

JS Functions
Medium
25 min

Middlewares

Compose async middleware functions into one onion-style pipeline where each step can run code before and after next().

JS Functions
Medium
25 min

Min By

Return the element whose iteratee value is smallest, skipping elements that produce no comparable value.

JS Functions
Easy
10 min

new Operator

Re-implement the new operator: create the object, link the prototype, run the constructor.

JS Functions
Medium
15 min

Number of Arguments

Return how many arguments a function was called with, and explain arguments vs rest vs Function.length.

JS Functions
Easy
5 min

Object.create

Implement Object.create, including null prototypes and property descriptors.

JS Functions
Easy
10 min

Observable

Build a minimal Observable with subscribe, unsubscribe, teardown, of/from creators and pipeable map and filter operators.

JS Functions
Hard
40 min

Omit

Create a shallow copy of an object without the listed keys.

JS Functions
Medium
10 min

Once

Wrap a function so that it runs at most once and later calls return the first result.

JS Functions
Easy
10 min

Partial

Pre-fill some of a function's arguments, with placeholders for positions supplied later.

JS Functions
Medium
15 min

Pick

Create a new object containing only the listed keys of a source object.

JS Functions
Easy
10 min

Pipe

Chain functions left to right so data flows through them in reading order.

JS Functions
Easy
10 min

Promise.all

Implement Promise.all: resolve with every result in order, or reject on the first failure.

JS Functions
Medium
20 min

Promise.allSettled

Implement Promise.allSettled: wait for every input and report each outcome in order.

JS Functions
Medium
15 min

Promise.any

Implement Promise.any: fulfill with the first success, or reject with an AggregateError.

JS Functions
Medium
20 min

Promise Implementation

Build a Promises/A+-style MyPromise with then, catch, finally, chaining and thenable adoption.

JS Functions
Hard
45 min

Promise Pool

Build a concurrency-limited task queue: tasks can be added at any time and at most N run at once.

JS Functions
Hard
30 min

Promise.race

Implement Promise.race: settle the same way as the first input to settle.

JS Functions
Easy
10 min

Promise.reject

Implement Promise.reject and explain why it never unwraps promises or thenables.

JS Functions
Easy
5 min

Promise.resolve

Implement Promise.resolve, including promise pass-through and thenable adoption.

JS Functions
Medium
15 min

Promise Timeout

Wrap a promise so it rejects with a TimeoutError if it doesn't settle in time, without leaking timers.

JS Functions
Medium
15 min

Promise.withResolvers

Implement Promise.withResolvers to create a promise you can settle from outside its executor.

JS Functions
Easy
10 min

Promisify

Convert a Node-style callback function into one that returns a promise.

JS Functions
Medium
15 min

Promisify II

Extend promisify with a custom-implementation symbol, like Node's util.promisify.custom.

JS Functions
Medium
20 min

Pub/Sub Store (Mini Redux)

Implement createStore with getState, dispatch and subscribe: the core of Redux in about 50 lines.

JS Functions
Medium
25 min

Range

Generate an array of numbers from start up to, but not including, end with an optional step.

JS Functions
Easy
10 min

Range Right

Generate the same numbers as range(start, end, step) but in descending order of generation.

JS Functions
Easy
10 min

Retry with Backoff

Retry a failing async operation with exponential backoff and a predicate that decides which errors are worth retrying.

JS Functions
Medium
20 min

Run Async Tasks in Series

Run a list of async functions one after another, passing each result to the next and stopping at the first failure.

JS Functions
Medium
15 min

Set

Write a value at a nested path, creating missing objects and arrays along the way.

JS Functions
Medium
25 min

setInterval with setTimeout

Re-implement setInterval and clearInterval using only chained setTimeout calls.

JS Functions
Medium
20 min

Signals (Fine-Grained Reactivity)

Implement createSignal, createEffect, createMemo, batch and untrack with automatic dependency tracking and glitch-free updates.

JS Functions
Hard
60 min

Size

Return the size of a collection: length for arrays and strings, size for Map and Set, key count for objects.

JS Functions
Easy
10 min

Sleep

Write a promise-based sleep(ms) and explain why it pauses an async function but not the thread.

JS Functions
Easy
5 min

Spreadsheet Evaluator

Build a spreadsheet engine: parse cell formulas, evaluate references and ranges, recompute dependents on change and detect cycles.

JS Functions
Hard
60 min

Squash Object

Flatten a nested object into a single level whose keys are dot-separated paths.

JS Functions
Medium
20 min

String Repeat and Pad

Implement repeat, padStart and padEnd without the built-in string methods, matching their edge-case behaviour.

JS Functions
Easy
15 min

Table of Contents

Build a nested table of contents from the h1–h6 headings in a document, generating unique anchor ids and rendering it as nested lists.

JS Functions
Hard
35 min

Template Engine

Build a {{ }} interpolation engine with dotted paths, HTML escaping, raw {{{ }}} output, filters and a compile step.

JS Functions
Medium
30 min

Text Search Highlight

Wrap every case-insensitive match of the query words in <b> tags, merging overlapping and adjacent matches.

JS Functions
Medium
25 min

Throttle

Limit a function to at most one call per wait window, with leading and trailing calls.

JS Functions
Medium
20 min

Type Utilities

Write reliable checks for JavaScript's primitive types, including the null and boxed-value traps.

JS Functions
Easy
15 min

Type Utilities II

Write type checks for non-primitive values: arrays, functions, objects and plain objects.

JS Functions
Medium
15 min

Undo/Redo History

Implement an undoable value with past and future stacks, redo invalidation, no-op detection and a bounded history size.

JS Functions
Medium
20 min

Union By

Merge several arrays into one list of unique elements, where uniqueness is decided by an iteratee.

JS Functions
Medium
15 min

Unique Array

Remove duplicate values from an array while keeping the first occurrence of each, in order.

JS Functions
Easy
10 min

Query String Parse and Stringify

Parse a URL query string into an object (with repeated keys as arrays) and serialise it back, handling encoding, + as space and malformed input.

JS Functions
Medium
25 min

Virtual DOM Diff (Keyed Children)

Patch the real DOM from an old and a new virtual tree, reusing nodes by type and key and moving keyed children instead of recreating them.

JS Functions
Hard
50 min

Virtual DOM: createElement and render

Implement h() to build virtual DOM nodes and render() to turn them into real DOM, with attributes, styles, events and function components.

JS Functions
Hard
35 min