Map, filter, reduce patterns
📖 Scenario: You work at a small fruit store. You have a list of fruit prices and want to do some simple calculations to help with pricing and sales.
🎯 Goal: Learn how to use map, filter, and reduce in Swift to transform, select, and combine data from a list.
📋 What You'll Learn
Create an array of fruit prices
Create a discount rate variable
Use
map to apply the discount to all pricesUse
filter to find prices above a thresholdUse
reduce to calculate the total of filtered pricesPrint the final total
💡 Why This Matters
🌍 Real World
Stores and shops often need to update prices, apply discounts, and calculate totals quickly and clearly.
💼 Career
Knowing how to use map, filter, and reduce is useful for data processing tasks in many programming jobs, especially in apps that handle lists of items.
Progress0 / 4 steps