func sumOf(numbers: Int...) -> Int {
var result = 0
for number in numbers {
result += number
}
return result
}
let a1 = sumOf(numbers: 1, 2, 4, 10)
func sampleOfSum(nums: Int...) -> Int {
return sumOf(numbers: nums)// Error: Cannot convert value of type '[Int]' to expected argument type 'Int'
}
Asked
Active
Viewed 28 times
0
-
yes, same question, thanks. – JerryZhou Jan 25 '17 at 05:04
-
i personally would prefer the [Int] function parameters. in the most cases you calculare over an array – muescha Jan 25 '17 at 05:25
-
btw: a sum over an array you write faster like this: `let sum = [4,5,9].reduce(0,{$0+$1})` – muescha Jan 25 '17 at 05:28
-
@muescha good suggestion. – JerryZhou Jan 25 '17 at 06:05