mirror of
https://github.com/bendtherules/buildit-weather-app.git
synced 2026-08-18 13:42:14 +00:00
Add summary calc to single day
This commit is contained in:
@@ -21,6 +21,28 @@ export class SingleDayForecast extends React.Component<SingleDayForecastProps, {
|
|||||||
this.props = this.props;
|
this.props = this.props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calcSummary(): { avgTemp: number, avgHumidity: number } {
|
||||||
|
let avgTemp: number, avgHumidity: number;
|
||||||
|
{
|
||||||
|
const sumTemp = this.props.forecastCurrentDay.reduce(
|
||||||
|
(prevSum, currentForecast) => {
|
||||||
|
return prevSum + currentForecast.main.temp;
|
||||||
|
},
|
||||||
|
0);
|
||||||
|
|
||||||
|
const sumHumidity = this.props.forecastCurrentDay.reduce(
|
||||||
|
(prevSum, currentForecast) => {
|
||||||
|
return prevSum + currentForecast.main.humidity;
|
||||||
|
},
|
||||||
|
0);
|
||||||
|
|
||||||
|
avgTemp = sumTemp / this.props.forecastCurrentDay.length;
|
||||||
|
avgHumidity = sumHumidity / this.props.forecastCurrentDay.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { avgTemp, avgHumidity };
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="SingleDayForecast">
|
<div className="SingleDayForecast">
|
||||||
|
|||||||
Reference in New Issue
Block a user