As much as I like FCC, the ES6 part is in my opinion a bit haphazardly designed.
The ES6 Destructuring Nested Objects example is as follow:
const LOCAL_FORECAST = {
today: { min: 72, max: 83 },
tomorrow: { min: 73.3, max: 84.6 }
};
function getMaxOfTmrw(forecast) {
"use strict";
// change code below this line
const maxOfTomorrow = undefined; // change this line
// change code above this line
return maxOfTomorrow;
}
console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6
I am trying to understand the core syntax of the Destructuring of the LOCAL_FORECAST
so If I am interested in the max
value for tomorrow
:
- I select the available Object on the Right hand side of the Expression
const something = forecast
- I want to destructure the
tomorrow
key value pair so I do something:
const {tomorrow:{....} } = forecast
- now I want to provide
maxOfTomorrow
frommax
const {tomorrow: { max: maxOfTomorrow}} = forecast
I really don’t get destructuring logic. How is all this coding mumbo-jumbo different from parsing the Object to quickly find the max of tomorrow with simple key-value pair parsing?