Skip to content

Instantly share code, notes, and snippets.

@pedrogimenez
Last active February 9, 2017 07:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pedrogimenez/809542e27f4bdcc680a0 to your computer and use it in GitHub Desktop.
Save pedrogimenez/809542e27f4bdcc680a0 to your computer and use it in GitHub Desktop.
swift.swift
func calculateAverage(total: Int, countOfNumbers: Int) -> Int {
return total / countOfNumbers
}
func average(algorithm: (Int, Int) -> Int, numbers: Int...) -> Int {
var countOfNumbers = 0
var total = 0
for number in numbers {
total += number
countOfNumbers++
}
return algorithm(total, countOfNumbers)
}
average(calculateAverage, 3, 3, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment