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].