Averages/Pythagorean means

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";
  tests=" no";
var ftest ="'is A >= G >= H ?" + tests +"'";
obj.test = ftest;

var str = JSON.stringify(obj, null, "\n");
str = str.replace(/"/g,"");
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:

The entire rosetta code section is a bit of a mess, it needs a serious look at it

The test uses deepEqual on an object, so you should be returning an object here

I am a little worried that it’ll be comparing floats to a large number of decimal places so might be rejecting your solution based on that, check carefully what your returned object is and compare it to the example

1 Like


I improved my solution (take a look above). The output is currently exactly (visually) the same as required but test will not pass anyway. I am little bit desperate , please if you have any other ideas… Thanks

You should be returning an object here

Make the three following changes:

  • Delete everything from the line where you stringify the object, including that line
  • return obj, NOT a string
  • delete the extra quotation marks you’ve added to obj.test

It should now pass, unless there’s weirdness with floating point numbers

1 Like

thank you very much! Finally it works