Quick Question about destructuring

Tell us what’s happening:

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

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

Link to the challenge:


So i’ve completed this challenge but im still pretty confused on how the destructuring part knows to reference the stats array over other arrays. If there was a second array named fakeStats which had the same variables with different values, how would it know which min or max to reference? Or is this simply outside the scope of using destructuring in this way?

screenshot

The part that you aren’t seeing in the code editor is that half is getting passed the stats object when it’s called. half() is a function that takes an object as its argument.

2 Likes