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
- JavaScriptCoding exercise
Array findLast / findLastIndex
EASYImplement findLast and findLastIndex — scan an array from the end for the last element matching a predicate.
15 minPractice - JavaScriptCoding exercise
Array.prototype.at
EASYImplement Array.prototype.myAt — return the element at a given index, supporting negative offsets from the end.
15 minPractice - JavaScriptCoding exercise
Array.prototype.every
EASYImplement Array.prototype.every — return false as soon as an element fails the predicate, true when empty.
15 minPractice - JavaScriptCoding exercise
Array.prototype.filter
EASYImplement Array.prototype.filter from scratch as a method on the array prototype.
15 minAmazon · Apple · Canva +1Practice - JavaScriptCoding exercise
Array.prototype.flat
EASYImplement Array.prototype.flat — flatten nested arrays to a given depth (default 1, Infinity for all levels), dropping holes.
15 minPractice - JavaScriptCoding exercise
Array.prototype.forEach
EASYImplement Array.prototype.forEach — run a callback on each element as (value, index, array), skipping sparse holes.
15 minPractice - JavaScriptCoding exercise
Array.prototype.includes
EASYImplement Array.prototype.includes — test membership with SameValueZero so NaN matches, honoring negative fromIndex.
15 minPractice - JavaScriptCoding exercise
Array.prototype.indexOf
EASYImplement Array.prototype.indexOf — first index of a value by strict equality, supporting a negative fromIndex.
15 minPractice - JavaScriptCoding exercise
Array.prototype.some
EASYImplement Array.prototype.some — return true as soon as any element passes the predicate, false when empty.
15 minPractice - JavaScriptCoding exercise
Array.prototype.square
EASYImplement a custom Array.prototype.square method that returns a new array with each value squared.
15 minByteDance · LinkedIn · UberPractice - JavaScriptCoding exercise
Chunk
EASYImplement a function that splits an array into groups of a given size, with the last group holding the remainder.
15 minPractice - JavaScriptCoding exercise
Compact
EASYImplement a function that returns a new array with every falsy value stripped out.
15 minPractice - JavaScriptCoding exercise
Data Merging
EASYImplement a function that consolidates rows sharing the same user into a single grouped record.
15 minCoinbase · Meta · OpenAI +3Practice - JavaScriptCoding exercise
Difference
EASYImplement a function that returns the elements from the first array that do not appear in the second.
15 minPractice - JavaScriptCoding exercise
Drop Right While
EASYImplement a function that drops trailing array elements as long as a predicate keeps returning truthy.
15 minPractice - JavaScriptCoding exercise
Drop While
EASYImplement a function that drops leading array elements as long as a predicate keeps returning truthy.
15 minPractice - JavaScriptCoding exercise
Fill
EASYImplement a function that replaces array elements with a given value between an optional start and end index.
15 minPractice - AlgorithmsCoding exercise
Find Duplicates in Array
EASYImplement a function that checks whether an array contains any duplicate numbers.
15 minPractice - JavaScriptCoding exercise
Find Index
EASYImplement a function that returns the index of the first array element matching a predicate, or -1 if none match.
15 minPractice - JavaScriptCoding exercise
Find Last Index
EASYImplement a function that returns the index of the last array element matching a predicate, or -1 if none match.
15 minPractice - AlgorithmsCoding exercise
Find Missing Number in Sequence
EASYImplement a function that returns the single missing number from a sorted sequence of integers.
15 minPractice - JavaScriptCoding exercise
From Pairs
EASYImplement a function that builds an object from an array of [key, value] pair tuples.
15 minPractice - JavaScriptCoding exercise
Intersection
EASYImplement a function that returns the unique values present in every input array.
15 minPractice - JavaScriptCoding exercise
Key By
EASYImplement lodash keyBy — index a collection into an object keyed by an iteratee's return, keeping the last item for each key.
15 minPractice - JavaScriptCoding exercise
Map.groupBy
EASYImplement Map.groupBy — group an iterable into a Map whose keys can be any value, preserving key insertion order.
15 minPractice - JavaScriptCoding exercise
Max By
EASYImplement a function that returns the array element producing the largest value when run through an iteratee.
15 minPractice - JavaScriptCoding exercise
Mean
EASYImplement a function that computes the arithmetic mean of the numbers in an array.
15 minPractice - JavaScriptCoding exercise
Min By
EASYImplement a function that returns the array element producing the smallest value when run through an iteratee.
15 minPractice - JavaScriptCoding exercise
nth
EASYImplement 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 minPractice - AlgorithmsCoding exercise
Optimal Stock Trading
EASYImplement a function that computes the maximum profit obtainable from one buy and one sell of a stock.
15 minPractice - AlgorithmsCoding exercise
Pair Sum
EASYImplement a function that finds two numbers in an array that add up to a given target.
15 minPractice - JavaScriptCoding exercise
Range
EASYImplement a function that builds an array of numbers from start up to end, stepping by a given increment.
15 minPractice - JavaScriptCoding exercise
Range Right
EASYImplement a function that builds an array of numbers from end down to start in descending order.
15 minPractice - JavaScriptCoding exercise
takeWhile
EASYImplement take and takeWhile — grab the leading n elements, or the leading run that satisfies a predicate.
15 minPractice - JavaScriptCoding exercise
times
EASYImplement times — invoke a function n times and collect the results into an array.
15 minPractice - JavaScriptCoding exercise
Unique Array
EASYImplement a function that returns a new array with duplicate values removed while preserving original order.
15 minPractice - JavaScriptCoding exercise
without
EASYImplement without — return a copy of an array with the given values excluded, matched by SameValueZero.
15 minPractice - JavaScriptCoding exercise
Array.prototype.concat
MEDIUMImplement Array.prototype.myConcat — merge arrays and values into a new array, spreading nested arrays one level deep.
25 minApplePractice - JavaScriptCoding exercise
Array.prototype.find
MEDIUMImplement Array.prototype.find and findLast — return the first or last element matching a predicate, or undefined.
25 minPractice - JavaScriptCoding exercise
Array.prototype.flatMap
MEDIUMImplement Array.prototype.flatMap — map each element, then flatten the mapped results by one level.
25 minPractice - JavaScriptCoding exercise
Array.prototype.map
MEDIUMImplement Array.prototype.myMap — return a new array with the callback applied to each element, skipping holes.
25 minAmazon · Apple · ByteDance +2Practice - JavaScriptCoding exercise
Array.prototype.reduce
MEDIUMImplement Array.prototype.myReduce — fold an array down to one value, handling sparse arrays and missing initial values.
25 minAdobe · Amazon · Apple +4Practice - JavaScriptCoding exercise
Array.prototype.reduceRight
MEDIUMImplement Array.prototype.reduceRight — fold an array right-to-left, throwing on an empty array with no initial value.
25 minPractice - JavaScriptCoding exercise
Array.prototype.splice
MEDIUMImplement Array.prototype.splice — remove and insert elements in place, returning the removed ones, with clamped indices.
25 minPractice - JavaScriptCoding exercise
classNames
MEDIUMImplement a utility that conditionally joins class name arguments into a single space-separated string.
25 minMetaPractice - JavaScriptCoding exercise
Count By
MEDIUMImplement a function that tallies how many array elements map to each key produced by an iteratee.
25 minPractice - AlgorithmsCoding exercise
Find Element in Rotated Array
MEDIUMImplement a function that locates a target integer in a sorted array that has been rotated at an unknown pivot.
25 minPremium questionPractice - JavaScriptCoding exercise
Flatten
MEDIUMImplement a function that recursively flattens a nested array into a single-level array.
25 minAirbnb · Amazon · Apple +10Practice - JavaScriptCoding exercise
Group By
MEDIUMImplement a function that buckets array elements into an object keyed by the value an iteratee returns for each.
25 minLinkedIn · ThoughtspotPractice - JavaScriptCoding exercise
Immutable Array Methods
MEDIUMImplement the ES2023 change-by-copy trio — toSorted, toReversed, and with — that copy an array instead of mutating it.
30 minPremium questionPractice - JavaScriptCoding exercise
Intersection By
MEDIUMImplement a function that intersects arrays by comparing values produced by an iteratee, keeping uniqueness.
25 minPractice - JavaScriptCoding exercise
Intersection With
MEDIUMImplement a function that intersects arrays using a user-supplied comparator to decide equality between elements.
25 minPractice - JavaScriptCoding exercise
Map Async
MEDIUMImplement a function that applies an async mapper to every item in an array and resolves with the results.
25 minAnthropic · Apple · ByteDance +4Practice - AlgorithmsCoding exercise
Maximum Product in Contiguous Array
MEDIUMImplement a function that finds the contiguous subarray with the largest product, handling negatives and zeros.
25 minPractice - AlgorithmsCoding exercise
Maximum Sum in Contiguous Array
MEDIUMImplement a function that finds the contiguous subarray with the largest sum.
25 minPractice - AlgorithmsCoding exercise
Maximum Water Trapped Between Walls
MEDIUMImplement a function that finds the maximum amount of water that can be trapped between two walls.
25 minPractice - JavaScriptCoding exercise
orderBy
MEDIUMImplement orderBy — stably sort objects by multiple keys, each ascending or descending.
25 minPractice - JavaScriptCoding exercise
partition
MEDIUMImplement partition — split an array into elements that pass a predicate and those that fail, in one pass.
25 minPractice - AlgorithmsCoding exercise
Smallest Element in Rotated Sorted Array
MEDIUMImplement a function that finds the minimum value in a sorted array that has been rotated at an unknown pivot.
25 minPremium questionPractice - JavaScriptCoding exercise
Union By
MEDIUMImplement a function that returns unique values across input arrays using a custom iteratee to determine identity.
25 minPractice - JavaScriptCoding exercise
useArray
MEDIUMImplement a hook that manages an array along with helpers to push, remove, update, and clear items.
25 minUberPractice - JavaScriptCoding exercise
zip / unzip
MEDIUMImplement zip, unzip, and zipObject — interleave arrays into tuples and back, padding ragged lengths.
25 minPractice - JavaScriptCoding exercise
classNames II
HARDExtend the classNames utility to dedupe class names and resolve function arguments lazily.
40 minPractice - JavaScriptCoding exercise
Data Selection
HARDImplement a function that filters an array of row objects by a flexible field-and-condition specification.
40 minAmazon · Meta · OpenAI +3Practice