You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -187,24 +187,20 @@ function userClicksOnEqualButton(button) {
187
187
constreplacedArray=data.map((item)=>
188
188
item==="x" ? "*" : item==="÷" ? "/" : item
189
189
);
190
-
// Check if the expression involves 0/0
191
-
// if (areYouDivindingByZero(replacedArray)) {
192
-
// screen.innerText = "You cannot divide by zero. Press AC";
193
-
// }
194
-
195
190
if(areYouDividingdZeroByZero(replacedArray)){
196
191
screen.innerText="0÷0 is an invalid format. Press AC";
197
192
}else{
198
193
letresult=eval(replacedArray.join(""));
194
+
lethistoryEntries=[[...replacedArray,"=",result]];// Used slice() at firest. But slice() is not sufficient because it only creates a shallow copy of the array, and modifications to the new array will still affect the original array. The spread syntax ([...replacedArray]), which creates a shallow copy as well, is a concise way to create a new array with the same elements as the existing array. While ensuring that modifications to historyEntries do not affect replacedArray, and vice versa.
0 commit comments