ES:6 Use Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
Hey I’ve got a question if anyone can help, how am I able to destructure the stats object without even putting a reference to stats in the “half” function?

I had the answer correct except I was using ( { stats: {max, min} } ) as my function parameters, rather than ( { max, min } ) which we’re given as the correct option. I don’t understand how I can reference the stats object without any mention of stats in the parameters.

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

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

Link to the challenge:

when you call the function you can pass in the object as argument, look for example at the tests:

half(stats) should be 28.015

1 Like

Oh I see! Thank you. I didn’t know you could call the function like that from a const.