fileter
let numarray = [1,2,3,4,5]
let newnumArray = numarray.filter { $0 < 3 } // 2までの値をフィルタリングする
print(newnumArray)
//出力結果
[1, 2]
reduce
let reduceArray = [1,2,3,4,5]
var total = reduceArray.reduce(0) { (num1, num2) -> Int in
return num1 + num2
}
print(total)
//出力結果
15
reduce もっと短く書く
let reduceArray = [1,2,3,4,5]
let total1 = reduceArray.reduce(0, +) // たしざん
let total2 = reduceArray.reduce(1, *) // かけざん
print(total1) //15
print(total2) //120
関数でMin、Maxを取得
let scores = [84, 76, 91, 62 ,80]
let min = scores.min()
let max = scores.max()
print(min) // 62
print(max) // 91