Tell us what’s happening:
So I thought the solution was just
const half = ({max,min}) => {
return (max + min) / 2.0;
}
But the solution said
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
Can someone explain why we had to return an identical function inside a function in order to solve this problem?
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