From c88521f6a1afc30df7caccc9494207ceda178667 Mon Sep 17 00:00:00 2001 From: Jirawat Boonkumnerd Date: Tue, 12 Oct 2021 18:38:52 +0700 Subject: [PATCH] perf: replace array.form with for loop --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d10f4ab..6a7bb8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,8 @@ function numberToWords(num: string): string { let output = EMPTY; const length = num.length; - Array.from(num).forEach((d, idx) => { + for (let idx = 0; idx < length; idx++) { + const d = num[idx]; const digitIdx = (length - idx - 1) % 6; const isMillion = length - 1 !== idx && digitIdx === 0; @@ -25,7 +26,7 @@ function numberToWords(num: string): string { output += LAN; } - return; + continue; } const isSib = digitIdx === 1; @@ -43,7 +44,7 @@ function numberToWords(num: string): string { if (isMillion) { output += LAN; } - }); + } return output; }