1st it will not have same key within that obj, if it’s a nested obj than you have to do deep destructuring (i.g. const { main: { content: { title } } } = obj) , and if it is a array of object u need to use iterator to iterate for value of each key and cheke by condition for what u want
i know that the function doesn’t “know” anything.
in my code you can see that i didn’t specify any object, i added the values as an arguments
but those values can be related to any other object…
the arguments for the function were {min,max} & can be taken from any other object.
let’s say i have another object named lamps which also holds min & max values how the function decides form which object the values will be taken form.
i will just note that i took the code from the solution…
i.e const half = ({min,max})
see the full code bellow
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 = ({min,max}) => (max + min) / 2.0;
// Only change code above this line
;
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
That is not the full code. You are missing the actual call to the function which is where the object you want to use is passed in. The function will use the object you pass to it, destructuring the properties as specified.
You’re not the first one to be confused about this. If you look at the lower left of the screen, you’ll see that the function is called by the tests with the stats object as parameter:
half(stats)
That’s how the function knows which object to destructure.