Swift: Add 1 to each element of an integer array
By somaria
2022-11-13
import Cocoa /* Create an array of 5 integers */ var myArray = [1, 2, 3, 4, 5] /* print the array */ print(myArray) /* using closure, add 1 to each element of the array */ myArray = myArray.map({$0 + 1}) /* print the array */ print(myArray)

Output

[1, 2, 3, 4, 5]

[2, 3, 4, 5, 6]