Strengthen problem-solving skills with data structures and algorithms, from arrays and strings to searching and traversal.
Start coding without an account. Sign in to save your work.
50 questions to explore
Choose a challenge. Make it work.
Write flatten(values): take an array that can contain other arrays and return a new array containing every non-array value, in its original left-to-right order.
Implement arrayReduce to recreate the core behavior of Array.prototype.reduce using a loop. Work with a standalone function that receives the array as its first argument.
Implement flattenObject(object). Convert nested object properties into a new flat object whose keys are dot-separated paths. Preserve each leaf value without changing the input. For example, { user: { name: "Ada" } } becomes { "user.name": "Ada" }. Arrays are leaf values in this exercise; use Flatten Array for array flattening.
Extend the class-name utility to deduplicate CSS classes, remove classes explicitly disabled later, and resolve function values. Process arguments and nested arrays in order to produce a clean class string. This version uses an ordered set of individual CSS tokens. A later falsy object flag removes its class, and a later truthy flag can enable it again.
Write countFrequencies(values) to count how often each primitive value appears in a nested array. Return a new Map whose keys follow the order in which the values are first encountered during a depth-first, left-to-right traversal.
Implement mapAsyncLimit(items, mapper, limit). Map every item using a possibly asynchronous callback while allowing at most limit calls to be in flight at once. Start another item as soon as a slot becomes free, and return results in input order even when tasks finish out of order.
Implement deepEqual(left, right) to compare values by their contents rather than only their references. Walk nested arrays and plain objects and decide whether both structures contain the same values. This exercise focuses on primitives, arrays, and plain objects. Arrays can be sparse, so an absent slot is different from a present slot containing undefined.
Implement dataSelection(rows, requirement) , a small filtering engine for an array of records. A requirement can test a field or combine other requirements with nested AND, OR, and NOT groups. Use { all: [...] } for AND, { any: [...] } for OR, and { not: requirement } for negation. A field rule has { field, operator, value } . For example, a dashboard could select active developers whose experience is at least two years.
Implement deepOmit(value, keys) to produce a copy of a nested structure with selected object properties removed wherever they occur. Traverse plain objects and arrays. Removing a key from an object must not remove an array position with the same string name.
Implement unsquashObject to reconstruct nested objects from dot-delimited paths.
20 of 50 questions loaded