April 2017
Intermediate to advanced
316 pages
9h 33m
English
And finally, let's implement the flatten function in terms of reduce:
func flattenIntermsOfReduce<Element>(elements: [[Element]]) -> [Element] { return elements.reduce([]) { $0 + $1 } } let flattened = flattenIntermsOfReduce(elements: aTwoDimArrayOfNumbers)
flattened will be [1, 3, 5, 2, 4, 6].
Read now
Unlock full access