Array Methods Workout
Five practical tasks that drill map, filter, reduce, sort and flatMap against realistic data.
Given an array of order objects, use map, filter, reduce, sort and flatMap to answer five business questions without mutating the source data.
Requirements
- Return only shipped orders
- Compute revenue per customer
- Find the highest-value order without mutating the input
- Group orders by status and flatten all line items
Need a reference?
Refresh the concepts before attempting the challenge on your own.
MDN: Array referenceCompare with the solution
Finish your attempt first, then open the reference solution to compare trade-offs.
Study the worked array patternsTasks
- Return only shipped orders.
- Compute revenue for each customer.
- Find the highest-value order without mutating the source array.
- Group orders by status.
- Produce a flat list of line items across all orders.
Rules
Prefer pure functions. Avoid for loops unless the task explicitly benefits from early exit.
Want more like this?
Browse the full exercises library, organised by topic.
Related learning
Data Types
Deep dive into JavaScript data types: numbers, strings, arrays, and array methods
Programming / JavaScript
An Introduction to JavaScript
Learn what JavaScript is, its history, and how to get started with tools and the developer console
Programming / JavaScript
JavaScript Fundamentals
Master the basics: Hello World, code structure, variables, data types, and type conversions
Programming / JavaScript