Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. //Map
  2. //Loops over a collection and applies the same operation to each element in the collection.
  3.  
  4. var numberArray = [1,2,3,4,5]
  5.  
  6. var newArray = numberArray.map( {(value:Int) -> Int in
  7. return value*2
  8. })
  9.  
  10. //or quicker
  11. var newArray = numberArray.map{$0*2}
  12.  
  13. //newArray = [2,4,6,8,10]
Add Comment
Please, Sign In to add comment