Kotlin function which counts standard deviation
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