
上QQ阅读APP看书,第一时间看更新
The map function
The map function is a higher-order function that solves the problem of transforming the elements of an array using a function. Consider the following example:
let numbers = [10, 30, 91, 50, 100, 39, 74]
var formattedNumbers: [String] = []
for number in numbers {
let formattedNumber = "\(number)$"
formattedNumbers.append(formattedNumber)
}
let mappedNumbers = numbers.map{ "\($0)$" }