Array Methods interview questions
Practice 64 questions on array methods. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
64 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
Array.prototype.square
Implement a custom Array.prototype.square method that returns a new array with each value squared.
15 minJavaScript - EASY
Chunk
Implement a function that splits an array into groups of a given size, with the last group holding the remainder.
15 minJavaScript - EASY
Compact
Implement a function that returns a new array with every falsy value stripped out.
15 minJavaScript - EASY
Data Merging
Implement a function that consolidates rows sharing the same user into a single grouped record.
15 minJavaScript - EASY
Difference
Implement a function that returns the elements from the first array that do not appear in the second.
15 minJavaScript - EASY
Drop Right While
Implement a function that drops trailing array elements as long as a predicate keeps returning truthy.
15 minJavaScript - EASY
Drop While
Implement a function that drops leading array elements as long as a predicate keeps returning truthy.
15 minJavaScript - EASY
Fill
Implement a function that replaces array elements with a given value between an optional start and end index.
15 minJavaScript - EASY
Find Duplicates in Array
Implement a function that checks whether an array contains any duplicate numbers.
15 minAlgorithms - EASY
Find Index
Implement a function that returns the index of the first array element matching a predicate, or -1 if none match.
15 minJavaScript - EASY
Find Last Index
Implement a function that returns the index of the last array element matching a predicate, or -1 if none match.
15 minJavaScript - EASY
Find Missing Number in Sequence
Implement a function that returns the single missing number from a sorted sequence of integers.
15 minAlgorithms - EASY
From Pairs
Implement a function that builds an object from an array of [key, value] pair tuples.
15 minJavaScript - EASY
Intersection
Implement a function that returns the unique values present in every input array.
15 minJavaScript - EASY
Key By
Implement lodash keyBy — index a collection into an object keyed by an iteratee's return, keeping the last item for each key.
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
Max By
Implement a function that returns the array element producing the largest value when run through an iteratee.
15 minJavaScript - EASY
Mean
Implement a function that computes the arithmetic mean of the numbers in an array.
15 minJavaScript - EASY
Min By
Implement a function that returns the array element producing the smallest value when run through an iteratee.
15 minJavaScript - EASY
nth
Implement nth — return the element at index n, counting from the end when n is negative, so head is nth(0) and last is nth(-1).
15 minJavaScript - EASY
Optimal Stock Trading
Implement a function that computes the maximum profit obtainable from one buy and one sell of a stock.
15 minAlgorithms - EASY
Pair Sum
Implement a function that finds two numbers in an array that add up to a given target.
15 minAlgorithms - EASY
Range
Implement a function that builds an array of numbers from start up to end, stepping by a given increment.
15 minJavaScript - EASY
Range Right
Implement a function that builds an array of numbers from end down to start in descending order.
15 minJavaScript - EASY
takeWhile
Implement take and takeWhile — grab the leading n elements, or the leading run that satisfies a predicate.
15 minJavaScript - EASY
times
Implement times — invoke a function n times and collect the results into an array.
15 minJavaScript - EASY
Unique Array
Implement a function that returns a new array with duplicate values removed while preserving original order.
15 minJavaScript - EASY
without
Implement without — return a copy of an array with the given values excluded, matched by SameValueZero.
15 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
classNames
Implement a utility that conditionally joins class name arguments into a single space-separated string.
25 minJavaScript - MEDIUM
Count By
Implement a function that tallies how many array elements map to each key produced by an iteratee.
25 minJavaScript - MEDIUM
Find Element in Rotated Array
Implement a function that locates a target integer in a sorted array that has been rotated at an unknown pivot.
25 minAlgorithms - MEDIUM
Flatten
Implement a function that recursively flattens a nested array into a single-level array.
25 minJavaScript - MEDIUM
Group By
Implement a function that buckets array elements into an object keyed by the value an iteratee returns for each.
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
Intersection By
Implement a function that intersects arrays by comparing values produced by an iteratee, keeping uniqueness.
25 minJavaScript - MEDIUM
Intersection With
Implement a function that intersects arrays using a user-supplied comparator to decide equality between elements.
25 minJavaScript - MEDIUM
Map Async
Implement a function that applies an async mapper to every item in an array and resolves with the results.
25 minJavaScript - MEDIUM
Maximum Product in Contiguous Array
Implement a function that finds the contiguous subarray with the largest product, handling negatives and zeros.
25 minAlgorithms - MEDIUM
Maximum Sum in Contiguous Array
Implement a function that finds the contiguous subarray with the largest sum.
25 minAlgorithms - MEDIUM
Maximum Water Trapped Between Walls
Implement a function that finds the maximum amount of water that can be trapped between two walls.
25 minAlgorithms - MEDIUM
orderBy
Implement orderBy — stably sort objects by multiple keys, each ascending or descending.
25 minJavaScript - MEDIUM
partition
Implement partition — split an array into elements that pass a predicate and those that fail, in one pass.
25 minJavaScript - MEDIUM
Smallest Element in Rotated Sorted Array
Implement a function that finds the minimum value in a sorted array that has been rotated at an unknown pivot.
25 minAlgorithms - MEDIUM
Union By
Implement a function that returns unique values across input arrays using a custom iteratee to determine identity.
25 minJavaScript - MEDIUM
useArray
Implement a hook that manages an array along with helpers to push, remove, update, and clear items.
25 minJavaScript - MEDIUM
zip / unzip
Implement zip, unzip, and zipObject — interleave arrays into tuples and back, padding ragged lengths.
25 minJavaScript - HARD
classNames II
PREMIUMExtend the classNames utility to dedupe class names and resolve function arguments lazily.
40 minJavaScript - HARD
Data Selection
PREMIUMImplement a function that filters an array of row objects by a flexible field-and-condition specification.
40 minJavaScript