Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
I’ve done this with extended/longer version

const half = (stats) => {
    const { max, min } = stats;
    return (max + min) / 2.0; 
}

Which in the description is described as:

This effectively destructures the object sent into the function.

but it throws an error:

Destructuring should be used.

So the test expects just one line version:

const half = ({ max, min }) => (max + min) / 2.0;

The problem I’ve got with this statement is that I’m not sure how it knows which object max and min parameters to take as input? What if there is another object e.g. majorStats with the same parameters max and min.

How is it established which object to get as an input if this one line statement doesn’t mention this at all?

Your code so far


const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85
};

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0.

Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters

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

The half function has a parameter, stats, the value of that parameter depends on what argument is passed in when the function is called:

When you substitute the parameter for destructuring, then the argument instead o being assigned to a simple variable is assigned to {max, min}
(what the function does with the passed in argument is {max, min} = /* first argument passed in */)

Makes sense, I missed that line, thank you for quick response.