ES6: Use Destructuring Assignment to Pass an Object as a Function's Parameters problem

ES6: Use Destructuring Assignment to Pass an Object as a Function's Parameters problem
0

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters/

I have this code:

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half(stats) {
    // use function argument destructuring
    const { max,  min} = stats; 
    return (stats.max + stats.min) / 2.0;
  };
  // change code above this line

})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

I get error message: Destructuring was used.

Any ideas?

Parece que você criou o mesmo tópico ontem. Por favor, se for isso, não duplique tópicos.

Any ideas on this problem?

you need to use destructuring as function parameter, you haven’t, if you notice that test has the grey cross, so it means it is not passed

Thanks. Here is my code now:

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half(max, min) {
    // use function argument destructuring
     
    return (stats.max + stats.min) / 2.0;
  };
  // change code above this line

})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

It still doesn’t work.

Can you please help me out?

In your case, you passed in the object in max and min has value of undefined, that is not destructuring

Look again at the description if you can figure out how you should do it

Thanks for your input.

This is what I have now:

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; // do not change this line

  // change code below this line
  return function half(stats) {
    // use function argument destructuring
    const {max, min} = stats; 
    return (max + min) / 2.0;
  };
  // change code above this line

})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015

I get error: Destructuring was used.

Any ideas?

almost, but you need to use destructuring directly as function parameter, you have stats as function parameter and then you do {max, min} = stats;, well you need to combine the two things and use directly destructuring in the round parenthesis

Thanks for your answer.