From f37ed3397b47c8830dd658ed9eee598888553477 Mon Sep 17 00:00:00 2001 From: Sanan507 <227714367+Sanan507@users.noreply.github.com> Date: Fri, 11 Sep 2026 15:37:45 +0000 Subject: [PATCH] perf: optimize custom array input validation to avoid redundant iterations --- frontend/src/components/CustomArraySection.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/CustomArraySection.tsx b/frontend/src/components/CustomArraySection.tsx index 1996b0e..c7ff265 100644 --- a/frontend/src/components/CustomArraySection.tsx +++ b/frontend/src/components/CustomArraySection.tsx @@ -40,15 +40,18 @@ export function CustomArraySection({ return { validNumbers: [], invalidTokens: [], isArrayEmpty: true }; } - const tokens = rawText.split(',').map((t) => t.trim()).filter((t) => t.length > 0); + const rawTokens = rawText.split(','); const valid: number[] = []; const invalid: string[] = []; - for (const token of tokens) { - if (/^-?\d+$/.test(token)) { - valid.push(Number(token)); - } else { - invalid.push(token); + for (let i = 0; i < rawTokens.length; i++) { + const token = rawTokens[i].trim(); + if (token.length > 0) { + if (/^-?\d+$/.test(token)) { + valid.push(Number(token)); + } else { + invalid.push(token); + } } }