Potential issue with solution to destructuring assignment problem

Tell us what’s happening:
I found an older thread that was addressing a potential issue with this destructuring problem. In the accepted solution, there seems to be no reference to the stats object. The solution passes, but I don’t understand why. Am I correct to believe that the argument should be const half = ({max, min} = stats) and not simply const half = ({max, min} )?
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} = stats) => (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/89.0.4389.114 Safari/537.36.

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

Link to the challenge:

You are incorrect. The parameter deconstruction is the ({max, min}) part. An object gets passed to the half function. You destructure the necessary properites max and min from the object passed to the function (the argument), to be able to use them in the return value, which is the calculation (max + min) / 2.0

The example function is meant to work with any object which has keys min and max, you dont want to reference to the particular object. Like stated above, the function will accept an object as argument and the local variables in {min, max} will accept the values of the respective keys.

So if understood correctly, if I later want to call the function, that’s when I need to pass the object stats as a parameter? for example half(stats)?
Out of curiosity, how much harder does Javascript get, because sometimes I really need to focus and make my brain work hard to get these concepts down!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.