ES6 - Use Destructuring Assignment to Pass an Object as a Function's Parameters

Tell us what’s happening:
Describe your issue in detail here.
const half = ({max,min}) => (max + min) / 2.0;

how does this know what max/min am i referring to, since both max and min are element of an object and i have not mentioned object “stats” anywhere.
what if another object has an element with the same name?
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/ Safari/537.36

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

Link to the challenge:

It doesn’t matter how many objects with those properties exist anywhere in your code. It only matters what objects are passed to this function when it’s called.

1 Like

let x = half(stats)

When you call your half( ) function with parameter of stats object. It will desturcture your object and look for property/item named max and min.

You can try comment out the max/min line in stats object and see what prints out .
How you code has passed the test, is because FCC tested your function like this, so that you can focus on the mainly on the challenge:


Isn’t FCC amazing?
Happy coding. :smile:

1 Like

i should have seen the test case prior,it would have been obvious then!
thank you!