What does this print?
func sum(_ nums: Int...) -> Int {
var total = 0
for n in nums {
total += n
}
return total
}
print(sum(3, 5, 2))
print(sum(10))
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
10 10
Explanation:
Variadic parameters accept zero or more values as an array.
[/spoiler]