如何解决?在这种情况下,我应该得到2。
var r = [1, 3, 5]
r.max() // gives 5
ps:发布时的新品质标准 - 真是疯狂......
答案 0 :(得分:1)
这就是我要做的事情:
let array = [1, 3, 5]
if let (maxIndex, maxValue) = array.enumerated.max{ $0.element < $1.element } {
print("The max element is \(maxValue) at index \(maxIndex)")
}
else {
print("The array is empty, and has no max element or index.")
}