Skip to content

Instantly share code, notes, and snippets.

@milanpanchal
Forked from pedrogimenez/swift.swift
Created February 9, 2017 07:27
Show Gist options
  • Save milanpanchal/ead0908a1950ae13f7a81299aac36a8a to your computer and use it in GitHub Desktop.
Save milanpanchal/ead0908a1950ae13f7a81299aac36a8a 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