method of an array takes a function that takes one parameter of the same type as the array's elements, and returns a new value
Ex
let arr = [2, 4, 6, 8]
func doubleMe(i:Int) -> Int {
return i*2 }
let arr2 = arr.map(doubleMe) // [4, 8, 12, 16]
Shorter: (with anonymous function)
let arr = [2, 4, 6, 8]
let arr2 = arr.map ({
(i:Int) -> Int in
return i*2 })
Even shorter:
let arr = [2, 4, 6, 8]
let arr2 = arr.map {$0*2}