//定义两个简单的函数
    var sum = function(x,y){ return x+y;};  //求和函数
    var square = function(x){ return x*x;};  //数组中每个元素求它的平方
    
    var data = [99,87,97,96,85,86,98]
    var mean = (data.reduce(sum)/data.length).toFixed(2);
    var deviations = data.map(function(x){return x-mean;});
    var stddev = (Math.sqrt(deviations.map(square).reduce(sum)/(data.length))).toFixed(2);
    console.log("平均值:"+mean);
    console.log("偏差:"+deviations);
    console.log("标准差:"+stddev);
Last modification:February 7th, 2020 at 11:32 pm
如果觉得我的文章对你有用,请随意赞赏