Skip to content

Commit

Permalink
perf: simplify control flow
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed May 1, 2024
1 parent 64bfabc commit 2ca42dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/translators/dayOfWeek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export function transformDayOfWeekToText({
// If empty, skip it
if (dayOfWeek === undefined || dayOfWeek.length === 0) {
return undefined;
} else {
// Turn it into a string
const dayOfWeeks = dayOfWeek.map((dayCode) =>
i18next.t(`daysOfWeek:${dayCode}`),
);
const dayOfWeeksAsString = fromListToString(i18next, dayOfWeeks);

return i18next.t("fields.dayOfWeek.dayOfWeek", {
count: dayOfWeek.length,
dayOfWeek: dayOfWeeksAsString,
});
}

// Turn it into a string
const dayOfWeeks = dayOfWeek.map((dayCode) =>
i18next.t(`daysOfWeek:${dayCode}`),
);
const dayOfWeeksAsString = fromListToString(i18next, dayOfWeeks);

return i18next.t("fields.dayOfWeek.dayOfWeek", {
count: dayOfWeek.length,
dayOfWeek: dayOfWeeksAsString,
});
}
18 changes: 9 additions & 9 deletions src/translators/timeOfDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export function transformTimeOfDayToText({
// If empty, skip it
if (timeOfDay === undefined || timeOfDay.length === 0) {
return undefined;
} else {
// Turn it into a string
const timeOfDays = timeOfDay.map(formatString);
const timeOfDaysAsString = fromListToString(i18next, timeOfDays);

return i18next.t("fields.timeOfDay", {
timeOfDay: timeOfDaysAsString,
count: timeOfDays.length,
});
}

// Turn it into a string
const timeOfDays = timeOfDay.map(formatString);
const timeOfDaysAsString = fromListToString(i18next, timeOfDays);

return i18next.t("fields.timeOfDay", {
timeOfDay: timeOfDaysAsString,
count: timeOfDays.length,
});
}

0 comments on commit 2ca42dc

Please sign in to comment.