闭包作为参数
func getList(score:[Int],con:(Int)->Bool) -> [Int]
{
var newScore:[Int] = [Int]()
for item in score
{
if con(item)
{
newScore.append(item)
}
}
return newScore
}
//let newArray = getList(score: [75,60,95,45,85] ,con:{ (s:Int) -> Bool in
// return s>80
//})
let newArray = getList(score: [75,60,95,45,85], con:{$0>80})
print(newArray)
参考