From 68ea84a2cb90cc2bcf80f936636b0daa1729d355 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 9 Apr 2025 09:24:28 +0200 Subject: [PATCH] refactor(routes/api/recovery_codes): use .map instead of .forEach it doesn't make sense to use a forEach here, when all we do is push values into an array => just use .map directly as it returns an array --- src/routes/api/recovery_codes.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/routes/api/recovery_codes.ts b/src/routes/api/recovery_codes.ts index a98e1e38c..78be09966 100644 --- a/src/routes/api/recovery_codes.ts +++ b/src/routes/api/recovery_codes.ts @@ -43,12 +43,10 @@ function getUsedRecoveryCodes() { const dateRegex = RegExp(/^\d{4}\/\d{2}\/\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/gm); const recoveryCodes = recovery_codes.getRecoveryCodes(); - const usedStatus: string[] = []; - recoveryCodes.forEach((recoveryKey: string) => { - if (dateRegex.test(recoveryKey)) usedStatus.push(recoveryKey); - else usedStatus.push(String(recoveryCodes.indexOf(recoveryKey))); - }); + const usedStatus = recoveryCodes.map(recoveryKey => { + return (dateRegex.test(recoveryKey)) ? recoveryKey : String(recoveryCodes.indexOf(recoveryKey)) + }) return { success: true,