Skip to content

Instantly share code, notes, and snippets.

@robertmryan
Created August 9, 2020 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertmryan/92edae4b0ca41455ad26253770a7fc5c to your computer and use it in GitHub Desktop.
Save robertmryan/92edae4b0ca41455ad26253770a7fc5c to your computer and use it in GitHub Desktop.
extension Sequence where Element: FloatingPoint {
func mean() -> Element {
var count = 0
var sum: Element = 0
for element in self {
sum += element
count += 1
}
return sum / Element(count)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment