I have no idea how to pass the test. My output si practically identical (except new lines). I dont know if should I return some sort of object, or string or…? Please can you give me some advice?
Thanks in advance
Your code so far
function pythagoreanMeans (rangeArr) {
function getSum(total, num) {
return total + num;
}
function getProd(prod, num) {
return prod * num;
}
function getRecip(prod, num) {
return prod + (1/num);
}
var total = rangeArr.reduce(getSum);
var cnt = rangeArr.length;
var arit = total/cnt;
var product = rangeArr.reduce(getProd);
var geom = product **(1/cnt);
var recip = rangeArr.reduce(getRecip);
var harmn = cnt/recip;
var values = [arit, geom, harmn];
let obj = {
values: {
Arithmetic: values[0], // arithmetic
Geometric: values[1], // geometric
Harmonic: values[2] // harmonic
},
test: "ftest"
};
var tests;
if(arit >= geom && geom >= harmn){
tests= " yes";
}
else{
tests=" no";
}
var ftest ="'is A >= G >= H ?" + tests +"'";
obj.test = ftest;
var str = JSON.stringify(obj, null, "\n");
str = str.replace(/"/g,"");
console.log(str);
return str;
}
pythagoreanMeans([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
.
Link to the challenge: