A quick decision tree: map, filter or reduce?
Choosing the right method prevents tangled logic.
Use `map` when you need the same number of elements, but with a new shape or value. Use `filter` when you need only a subset. Use `reduce` when the result is one final value or one accumulated structure.
At scale, that rule saves you from writing giant loops that mix several responsibilities in one place.
map
Transforms each element.
- Prices to prices with tax
- Users to UI cards
filter
Keeps only the elements that match a rule.
- Only active users
- Only items with stock
reduce
Accumulates toward one final result.
- Total sales
- Grouped values by category