Skip to content

Commit c504132

Browse files
committed
replace 0 by the constant ZER0
1 parent 73bccb9 commit c504132

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ function convertToPercentage(button) {
4545

4646
function deteLastEntry(button) {
4747
if (button === "DE") {
48-
let newArray = data.slice(0, -1);
48+
let newArray = data.slice(ZERO, -1);
4949
screen.innerText = newArray.join("");
5050
data = newArray;
5151
if (screen.innerText === "") {
52-
screen.innerText = 0;
52+
screen.innerText = ZERO;
5353
}
5454
}
5555
}
5656

5757
function canUserAddDot(button) {
5858
if (button === ".") {
5959
var dotAllowed = true;
60-
for (var i = data.length - 1; i >= 0; i--) {
60+
for (var i = data.length - 1; i >= ZERO; i--) {
6161
console.log("data > " + data[i]);
6262
if (data[i] === ".") {
6363
dotAllowed = false;
@@ -67,7 +67,7 @@ function canUserAddDot(button) {
6767
}
6868
}
6969
if (dotAllowed) {
70-
if (data.length == 0) {
70+
if (data.length == ZERO) {
7171
data.push("0");
7272
} else if (operatorRegex.test(data[data.length - 1])) {
7373
data.push("0");
@@ -82,7 +82,7 @@ function deleteEverythingFromScreen(button) {
8282
if (button === "AC") {
8383
screen.innerText = "";
8484
data = [];
85-
screen.innerText = 0;
85+
screen.innerText = ZERO;
8686
}
8787
}
8888

@@ -94,15 +94,15 @@ function toggleSign(button) {
9494
// debugger
9595

9696
if (match) {
97-
let start = currentExpression.length - match[0].length;
97+
let start = currentExpression.length - match[ZERO].length;
9898
let end = currentExpression.length;
99-
let currentValue = Number(match[0]);
99+
let currentValue = Number(match[ZERO]);
100100

101101
if (!isNaN(currentValue)) {
102102
// If it's a number, toggle its sign
103103
currentValue = -currentValue;
104104
data = data
105-
.slice(0, start)
105+
.slice(ZERO, start)
106106
.concat(currentValue.toString().split(""), data.slice(end));
107107
screen.innerText = data.join("");
108108
}
@@ -113,7 +113,7 @@ function toggleSign(button) {
113113
function insertOpeningParenthesis(button) {
114114
if (button === "(") {
115115
let isOpenparenthesis = true;
116-
for (let i = data.length - 1; i >= 0; i--) {
116+
for (let i = data.length - 1; i >= ZERO; i--) {
117117
if (/^\d$/.test(data[i])) {
118118
isOpenparenthesis = false;
119119
break;
@@ -148,7 +148,7 @@ function handlingZeroFollowedByAdecimal(button) {
148148

149149
function removesDecimalPointIfPrecededByAnOperator(button) {
150150
if (operatorRegex.test(button)) {
151-
if (data.slice(-1)[0] === ".") {
151+
if (data.slice(-1)[ZERO] === ".") {
152152
data.pop();
153153
}
154154
button === "*" ? (button = "x") : button === "/" ? (button = "÷") : button;
@@ -196,7 +196,7 @@ function userClicksOnEqualButton(button) {
196196
}
197197

198198
function areYouDivindingByZero(array) {
199-
for (let i = 0; i < array.length - 2; i++) {
199+
for (let i = ZERO; i < array.length - 2; i++) {
200200
if (
201201
!isNaN(Number(array[i])) &&
202202
array[i + 1] === "/" &&
@@ -209,7 +209,7 @@ function areYouDivindingByZero(array) {
209209
}
210210

211211
function areYouDividingdZeroByZero(array) {
212-
for (let i = 0; i < array.length - 2; i++) {
212+
for (let i = ZERO; i < array.length - 2; i++) {
213213
if (array[i] === "0" && array[i + 1] === "/" && array[i + 2] === "0") {
214214
return true;
215215
}

0 commit comments

Comments
 (0)