I tried this for example but nothing seems to work.
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
function half({min = -0.75 ,max = 56.78}) {
// 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
Now I tried this and everything else is ok, except this: “destructuring was used”.
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(stats) {
// use function argument destructuring
const{min,max} = stats;
return (stats.max + stats.min) / 2.0;
};
// change code above this line
})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
this is destructuring, ok
so now you have variables min and max - so why are you still using stats.min and stats.max?
the other thing is that destructuring should be happening in place
when you do it in place, like in function parameters, you just need the stuff inside the graph parenthesis
In function parameters? I tried but it got really messy.
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(stats) {
// use function argument destructuring
const{min,max} = stats;
return (max + min) / 2.0;
};
// change code above this line
})();
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
Think of using the value passed to the parameter stats, like you are here.
const {min , max} = stats;
Only when using the parameter you do not need const or = stats because the value (the object) is being passed to the parameter.
const user = {
name: 'Joe',
age: 27
}
function getUser({name, age}) {
return name + ' is ' + age + ' years old'
}
getUser(user)
// returns "Joe is 27 years old"