Skip to content

Commit ef463c7

Browse files
committed
feat(JS) reuse operatorRegex variable in multiple places in code-base
1 parent b5537af commit ef463c7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ function canUserAddDot(button) {
7070
if (data[i] === ".") {
7171
dotAllowed = false;
7272
break;
73-
} else if (/[\/*\-+]/.test(data[i])) {
73+
} else if (operatorRegex.test(data[i])) {
7474
break;
7575
}
7676
}
7777
if (dotAllowed) {
7878
if (data.length == 0) {
7979
data.push("0");
80-
} else if (/[\/*\-+]/.test(data[data.length - 1])) {
80+
} else if (operatorRegex.test(data[data.length - 1])) {
8181
data.push("0");
8282
}
8383
data.push(".");
@@ -130,7 +130,7 @@ function insertOpeningParenthesis(button) {
130130
isOpenparenthesis = false;
131131
break;
132132
}
133-
if (/[\/*\-+]/.test(data[i])) {
133+
if (operatorRegex.test(data[i])) {
134134
break;
135135
}
136136
}
@@ -155,7 +155,7 @@ function handlingZeroFollowedByAdecimal(button) {
155155
}
156156

157157
function removesDecimalPointIfPrecededByAnOperator(button) {
158-
if (/[\/*\-+]/.test(button)) {
158+
if (operatorRegex.test(button)) {
159159
if (data.slice(-1)[0] === ".") {
160160
data.pop();
161161
}

0 commit comments

Comments
 (0)