Kotlin function which counts standard deviation Here is the code. The code should counts the standard deviation for double array, but also for Int arrays.

fun calculateSD(numArray: DoubleArray): Double {
var sum = 0.0
var standardDeviation = 0.0

for (num in numArray) {
    sum += num
}

val mean = sum / numArray.size

for (num in numArray) {
    standardDeviation += Math.pow(num - mean, 2.0)
}

val divider = numArray.size - 1

return Math.sqrt(standardDeviation / divider )
}
You may want to be more idiomatic when working with collections, for an instance:
import kotlin.math.pow
import kotlin.math.sqrt

fun sd(data: DoubleArray): Double {
    val mean = data.average()
    return data
        .fold(0.0, { accumulator, next -&gt; accumulator + (next - mean).pow(2.0) })
        .let { sqrt(it / data.size )
    }
}

BTW, I don't think that data.size - 1 is correct