I think there’s a mistake in this lesson, unless I’m missing something. How could this possibly be the solution, when the compiler doesn’t know which object the properties max and min are coming from?
console.log(half(stats)); // 28.015
// here we are calling the function by passing the object which gets destructured and only required values are passed to the function i.e. min & max.
I know its not provided.
The example or challenge is little incomplete but is doing its job perfectly fine.
There is no error in the code.
The only misunderstanding you have is about the arrow function.
Just assume
as
function half ({min, max}) {
return (min+max)/2.0;
}
both are the functions definition and both functions are doing exactly same task.
The challenge is missing one statement to call the function which is not important for that particular challenge to understand the challenge. Everything you need to understand or complete the challenge is given in the challenge itself.
The solution that you think is correct will give you some error, probably some assignment error because you wont pass the value to a function like that it.
The stats object will be passed on to function from function calling.
Example - half(stats) ;
I know which is missing from challenge but that’s not the point here.
For in-depth understanding of this, I would suggest you to review Arrow functions.