Dot product, ported from C to Swift
You can remove the size parameter as arrays know their own size in Swift, and use the zip, map and reduce functions to perform the computation rather than the C-style for loop, which is now unavailable in the latest versions of Swift (as is i++):

func mac(a: [Float], b: [Float]) -&gt; Float {
    return zip(a, b).map(*).reduce(0, +)
}



The zip function takes two arrays and makes a single array of tuples, with each tuple containing the nth element from each array.
The map function changes each element of the array with a user-supplied function. In this case, the multiplication operator is passed in, which multiplies each pair.
The reduce function performs the task of summing each result (starting at 0).