Map, Filter and Reduce on Arrays
Transforming arrays with functional higher-order functions.
Welcome
Swift's higher-order functions — `map`, `filter`, and `reduce` — transform collections without mutation. They make your intentions explicit and eliminate error-prone loops.
map — Transform Every Element
```swift
let nums = [1, 2, 3, 4]
let doubled = nums.map { $0 * 2 } // [2,4,6,8]
let strings = nums.map { "Item \($0)" } // ["Item 1","Item 2",...]
```
`map` applies a closure to each element and returns a new array of the results.
All lessons in this course
- Creating and Mutating Arrays
- Sorting, Searching and Slicing
- Map, Filter and Reduce on Arrays
- 2D Arrays and Nested Collections