有人可以为我分解这个代码示例吗?zip
并且reduce
有一定的意义,但是发生的事情combine:
让我感到困惑。任何帮助将不胜感激。
let a = [5, 6, 7]
let b = [3, 6, 10]
let pointsAlice = zip(a, b).reduce(0, combine: { $0 + ($1.0 > $1.1 ? 1 : 0) } )
let pointsBob = zip(b, a).reduce(0, combine: { $0 + ($1.0 > $1.1 ? 1 : 0) } )
print("\(pointsAlice) \(pointsBob)") // 1 1