我正在完成本书的第一章,无法弄清楚实验:
Add another variable to keep track of which kind of number was the
largest,as well as what that largest number was.
这是本书的代码:
let interstingNumbers = [ "Prime": [2,3,5,7,11,13,17],"Fibonacci": [1,1,2,8],"Square": [1,4,9,16,25,36],] var largest = 0 for (kind,numbers) in interstingNumbers { for number in numbers { if number > largest { largest = number } } } largest
解决方法
所以基本上你想要在将数字放入最大值的同时将其放在某处,例如变成一个名为largestKind的变量.