Tell us what’s happening:
As the title goes, I am failing to understand how an inline (anonymous?) function knows which object it should destructure. If the method used the ES5 method of
const half = (stats) => {
const {min, max} = stats;
return ((min+max)/2);
}
I can see how the "half function knows that we are talking about STATS and not STATSTEST (I added that object to the code).
My question is when we destructure the object in the parameter itself, neither STATS nor STATSTEST is mentioned anywhere so how does the function know which object it should destructure in the function?
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
};
//I added to test... how does our function know which object we want to destruct?
const statsTest = {
max: 0,
min: 0
}
// 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/84.0.4147.89 Safari/537.36
.
Challenge: Use Destructuring Assignment to Pass an Object as a Function’s Parameters
Link to the challenge: