Last active
February 9, 2017 07:27
-
-
Save pedrogimenez/809542e27f4bdcc680a0 to your computer and use it in GitHub Desktop.
swift.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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