Tsallaka zuwa abun ciki
Justice Tech School

Array Operations

map, filter, reduce, sorted, contains, firstIndex and joined are common.

Example
let n = [5, 2, 8, 1]
print(n.map { $0 * 2 })
print(n.filter { $0 > 2 })
print(n.reduce(0, +))
print(n.sorted(by: >))
print(n.contains(8), n.firstIndex(of: 8)!)
print(["a", "b"].joined(separator: "-"))

Exercise

Sum.

n.(0, +)

Quiz Test

What does map return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.