RosettaCodeData/Task/Averages-Root-mean-square/JavaScript/averages-root-mean-square-2.js

19 lines
334 B
JavaScript
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
(() => {
2016-12-05 22:15:40 +01:00
'use strict';
// rootMeanSquare :: [Num] -> Real
2017-09-23 10:01:46 +02:00
const rootMeanSquare = xs =>
Math.sqrt(
xs.reduce(
2016-12-05 22:15:40 +01:00
(a, x) => (a + x * x),
0
2017-09-23 10:01:46 +02:00
) / xs.length
2016-12-05 22:15:40 +01:00
);
2017-09-23 10:01:46 +02:00
return rootMeanSquare([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
2016-12-05 22:15:40 +01:00
2017-09-23 10:01:46 +02:00
// -> 6.2048368229954285
})();