From 43c374f24695aa9b775dd7934c1de9b1d6b2a85c Mon Sep 17 00:00:00 2001 From: Leslie Wong <79917148leslie@gmail.com> Date: Wed, 13 Oct 2021 21:01:30 +0800 Subject: [PATCH] :bug: fix: error when expression starts with digit --- jsbi-calculator.mjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsbi-calculator.mjs b/jsbi-calculator.mjs index af09317..4e5b573 100644 --- a/jsbi-calculator.mjs +++ b/jsbi-calculator.mjs @@ -141,10 +141,15 @@ function arrayizeExpression(expression) { acc[acc.length - 2] === "(" ) { acc[acc.length - 1] += newCur; + // newCur(digit) next to symbols } else if (checkArray.indexOf(acc[acc.length - 1]) > -1 && newCur) { acc.push(newCur); - } else { + // newCur(digit) next to digit + } else if (acc.length !== 0 && acc[acc.length -1]) { acc[acc.length - 1] += newCur; + // newCur(digit) in the front of the expression + } else { + acc.push(newCur); } } return acc;