Created
May 11, 2016 08:18
-
-
Save luish/e5049de1c373139af88b8849bbc8ddee to your computer and use it in GitHub Desktop.
This file contains 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
import Foundation | |
struct Math { | |
static func standardDeviation(values: [Double]) -> Double { | |
let squaredAvgDiff = values.map { pow($0 - average(values), 2)} | |
let sum = squaredAvgDiff.reduce(0) {$0 + $1} | |
return sqrt(sum / Double(values.count)) | |
} | |
static func average(values: [Double]) -> Double { | |
return values.reduce(0) {$0 + $1} / Double(values.count) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment