const map = function (a, ...args) { return a.map(...args); }; const reduce = function (a, ...args) { return a.reduce(...args); }; const sum = (x, y) => x + y; const square = x => x * x; let data = [1, 1, 3, 5, 5]; let mean = reduce(data, sum) / data.length; console.log('print avage:', mean); let deviations = map(data, x => x - mean); console.log('deviations:', deviations); let stddev = Math.sqrt(reduce(map(deviations, square), sum) / (data.length - 1)); console.log('stddev:', stddev);