소스 검색

fix result position

Bernadette Elena Hammerle 3 년 전
부모
커밋
f5c50b513b
2개의 변경된 파일11개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 3
      src/Addition.js
  2. 8 1
      src/Subtraction.js

+ 3 - 3
src/Addition.js

@@ -404,9 +404,9 @@ function Addition() {
 
   const finishCalculation = () => {
     document.getElementById("idmtResultSteps").innerHTML = "";
-    let resCalc = resArr.filter(n => n !== " ").join("");
-    setResultsGrid([{number: resCalc}]);
-    resCalc = parseFloat(resCalc);
+    let resCalc = resArr.join("");
+    setResultsGrid([{number: resCalc.replace(/ /g, " ")}]);
+    resCalc = parseFloat(resCalc.replace(/ /g, ""));
 
     let message = "";
     if(resCalc === realResult){

+ 8 - 1
src/Subtraction.js

@@ -458,7 +458,14 @@ function Subtraction() {
     if(resCalc.startsWith(".")){
       resCalc = "0" + resCalc;
     }
-    setResultsGrid([{number: resCalc}]);
+
+    let maxLen = Math.max(...numbers.map(x => x.length));
+    let resStr = resCalc;
+    while(maxLen > resStr.length){
+      resStr = " " + resStr;
+    }
+
+    setResultsGrid([{number: resStr}]);
     resCalc = parseFloat(resCalc);
 
     let message = "";