Tell us what’s happening:
I don’t get why in this case I don’t need to call stats inside the function. Is it because it is the only object that there is?
I use return function half({max, min}) {}
, but does it works because there is only an object that has max
and min
properties and so as good practive I should call stats
when using Destructuring Assignment like in the examples, or it just works like that?
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
};
const half = (function() {
"use strict"; // do not change this line
// change code below this line
return function half({max, min}) {
// use function argument destructuring
return (max + min) / 2.0;
} // change code above this line
})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters/