Skip to content

Instantly share code, notes, and snippets.

@SlaunchaMan
Created June 3, 2014 18:03
Show Gist options
  • Select an option

  • Save SlaunchaMan/c234254fa15450ba8f65 to your computer and use it in GitHub Desktop.

Select an option

Save SlaunchaMan/c234254fa15450ba8f65 to your computer and use it in GitHub Desktop.
Swift Averages
func sumOf(numbers: Int...) -> Int {
var sum = 0
for number in numbers {
sum += number
}
return sum
}
sumOf()
sumOf(42, 597, 12)
func averageOf(numbers: Int...) -> Int {
var sum = sumOf(numbers)
return sum / numbers.count
}
averageOf(1, 2, 3)
@eonist

eonist commented Mar 23, 2017

Copy link
Copy Markdown

What about [0,0,0,0,5].avg//1

Should be 5 no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment