Tell us what’s happening:
The values are being properly passed due to internal returns, but the std-dev, variance, means seem to be overshooting the projected values (rounded to 3 decimal places…), sometimes minutely, others somewhat radically. Can anybody help me understand why?
Your code so far
function standardDeviation(a) {
var mean = Math.floor(
(a.reduce( (t, el) => {
t+=el;
return t; }) /a.length)
*1000)/1000;
console.log(`Mean is passing as ${mean}. \n`);
var variance = Math.floor((a.map((el, t) => {
t+=Math.floor(Math.pow((el-mean),
2)*1000)/1000;
return t; }) .reduce(
(el, t) => { t+= el;
return Math.floor(t*1000)/1000; }) /a.length)
*1000)/1000;
console.log(`Variance is passing as ${variance}.\n`);
var stddev = Math.floor(Math.sqrt(variance)
*1000)/1000;
console.log(`Standard deviation is
passing as ${stddev}.\n `);
return stddev;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
.
Challenge: Cumulative standard deviation
Link to the challenge: