JSFiddle - React, Tailwind, and code Playground

by PiereDome

JavaScript

//For today's challenge, you should calculate some simple statistical values based on a list of values. Given this data set, write functions that will calculate:
//  The mean value
//  The variance
//  The standard deviation
//  Obviously, many programming languages and environments have standard  functions for these (this problem is one of the few that is really easy to solve in Excel!), but you are not allowed to use those! The point of this problem is to write the functions yourself. 

Calc = (function() {
    function findMeanValue(list) {
        var n = list.length;
        var a = 0;
        for (i = 0; i < n; i++) {
            a += list[i];
        }
        return a / n;
    }
    function findVariance(list) {
        var n = list.length;
        var u = findMeanValue(list);
        v = 0;
        for(i=0;i<n;i++){
            v += Math.pow(list[i]-u,2);
        }
        return v;
    }
    return {
        mean: findMeanValue,
        variance: findVariance,
        standardDev: function(list) {

        }
    };
})();

alert(Calc.variance([0, 1, 2,3]));