Tell us what’s happening:
Can someone explain the original code for this assignment? I’m confused by the apparent existence of two variables called, “half”. It appears there is a const variable named half. This half gets it’s value by calling an anonymous function which calls a function named half. Is that correct? Using “half” twice seems needlessly confusing to me.
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(stats) {
// use function argument destructuring
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
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:63.0) Gecko/20100101 Firefox/63.0.
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