Map an array to another array

 Problem

I have an array and want to map its values to a different array, based on a given transformation.



 Recipe


// Initialize the Array
var a = [1,2,3,4,5,6]

// Map values to their doubles: 1->2, 2->4, etc.

var b = a.map { $0 * 2 }
print(b)
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground