How does half know of where to get max and min

Tell us what’s happening:
Describe your issue in detail here.
Hello, the challenge is solved, but I still am not understanding how the functionality works.

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

is the statement in question, how does it relate to stats. I don’t need the connection.

  **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
};

// Only change code below this line
const half = ({max, min}) => (max + min) / 2.0; 
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

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

Link to the challenge:

They’re not connected.

The function pulls the max and min properties from the first parameter and puts them in separate variables for you to reference inside the function definition.

stats just happens to have a max and min property.


Here’s what it might look like without using destructuring:

const half = (someObject) => (someObject.max + someObject.min) / 2.0; 

(I used the name someObject because the parameter could be any arbitrary object)

2 Likes