From b582de3dc64b89ca4ba2476dc3b2a599633bc842 Mon Sep 17 00:00:00 2001 From: brage-andreas Date: Fri, 13 Sep 2024 13:57:43 +0200 Subject: [PATCH] refactor: simplify ternary --- src/profile/components/Settings/Penalties/Rules.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/profile/components/Settings/Penalties/Rules.tsx b/src/profile/components/Settings/Penalties/Rules.tsx index 26b3b137..c5f1dc4f 100644 --- a/src/profile/components/Settings/Penalties/Rules.tsx +++ b/src/profile/components/Settings/Penalties/Rules.tsx @@ -15,11 +15,13 @@ interface IProps { const inFuture = (date: string) => new Date(date) > new Date(); const getLatestRuleSet = (rules: IMarkRule[]): IMarkRule => { - return rules.reduce( - (latest, rule) => - !inFuture(rule.valid_from_date) && rule.valid_from_date > latest.valid_from_date ? rule : latest, - rules[0] - ); + return rules.reduce((latest, rule) => { + if (inFuture(rule.valid_from_date)) { + return latest; + } + + return rule.valid_from_date > latest.valid_from_date ? rule : latest; + }, rules[0]); }; export const Info = ({ rules }: IProps) => {