reduce use of .reduce on arrays

This commit is contained in:
Matt Walsh committed 2023-01-06 16:12:39 -06:00
1 parent 77137f665d
commit 656f099b60
3 files changed
+4 -17

No files matched your search

+1 -8
View File
@@ -125,14 +125,7 @@ const testActive = (data) => {
};
// test for any active warnings
const testWarning = (categorized) => Object.values(categorized).reduce(
(prevType, type) => (
prevType || type.reduce(
(prevAlert, alert) => prevAlert || !!(alert.isWarning && alert.isActive),
false,
)),
false,
);
const testWarning = (categorized) => Object.values(categorized).some((type) => (type.some((alert) => !!(alert.isWarning && alert.isActive))));
// show the alert dialog
const alertButton = () => {
+3 -6
View File
@@ -117,10 +117,7 @@ const showDetailOutlook = async (position, daysToGet) => {
}
// determine if all detail data is present
const allDataPresent = data.reduce(
(prevDay, day, dayIndex) => (!daysToGet[dayIndex] || Object.values(day).reduce((prevCategory, cur) => (cur !== undefined) && prevCategory, false)) && prevDay,
false,
);
const allDataPresent = data.every((day, dayIndex) => (!daysToGet[dayIndex] || Object.values(day).every((cur) => (cur !== undefined))));
if (!allDataPresent) {
await getRemainingData(daysToGet);
}
@@ -135,7 +132,7 @@ const analyzeDetailData = (position) => {
const isModerate = testModerate(inside);
// see if we're inside any areas
const isInside = inside.reduce((prev, day) => prev || day, false);
const isInside = inside.some((day) => day);
// show the button
updateButtonState(!isInside, isModerate);
@@ -237,7 +234,7 @@ const labelSortAlgorithm = (a, b) => {
return bDN - aDN;
};
const testModerate = (days) => days.reduce((prevDay, day) => prevDay || (day?.reduce?.((prevArea, area) => prevArea || redIconLabel.includes(area.LABEL), false) ?? false), false);
const testModerate = (days) => days.some((prevDay, day) => (day?.some?.((area) => redIconLabel.includes(area.LABEL)) ?? false));
// update button state
const updateButtonState = (hide, isModerate) => {
-3
View File
@@ -23,9 +23,6 @@ let isDark;
const readDarkMode = () => {
isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
// if (redraw) {
// formatData(formatData.fcst ?? false, formatData.obs ?? false);
// }
};
readDarkMode();