April 2017
Intermediate to advanced
316 pages
9h 33m
English
The filter function takes a function that, given an element in array, returns Bool, indicating whether the element should be included in the resulting array. The filter method is declared as follows in Swift standard library:
public func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> [Element]
The definition is similar to the map method with the following differences:
Let's examine the following code to understand how it works:
let numbers = [10, 30, 91, 50, 100, 39, 74] let evenNumbers = numbers.filter { $0 % 2 == 0 }
The resulting evenNumbers ...
Read now
Unlock full access