|  | @@ -37,7 +37,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const handleInput = (e) => {
 | 
	
		
			
				|  |  |      setInput(e.target.value);
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const handleResChange = (e) => {
 | 
	
		
			
				|  |  |      if(typeof e === "string"){
 | 
	
	
		
			
				|  | @@ -53,7 +53,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        // add input number to result array
 | 
	
		
			
				|  |  |        resArr.unshift(imdtRes);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const handleCarryChange = (e, nosLeft) => {
 | 
	
		
			
				|  |  |      if(e.keyCode === 13){
 | 
	
	
		
			
				|  | @@ -65,7 +65,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |           // if stop after first iteration, numbers left is undefined at first
 | 
	
		
			
				|  |  |           (isNaN(nosLeft) && realResult.toString().length === 1 && noCarry)){
 | 
	
		
			
				|  |  |          nosLeft = 0;
 | 
	
		
			
				|  |  | -        handleResChange(" ")
 | 
	
		
			
				|  |  | +        handleResChange(" ");
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        if(nosLeft === 0){
 | 
	
	
		
			
				|  | @@ -77,19 +77,19 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const handleSubmit = (e) => {
 | 
	
		
			
				|  |  |      startCalculation();
 | 
	
		
			
				|  |  |      e.preventDefault(); // avoid page reload
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const startCalculation = () => {
 | 
	
		
			
				|  |  | -    if (input.includes("-")){
 | 
	
		
			
				|  |  | +    if(input.includes("-")){
 | 
	
		
			
				|  |  |        let numbers = input.split("-").map(x => parseFloat(x.replace(",",".")));
 | 
	
		
			
				|  |  | -      let realRes = numbers[0]
 | 
	
		
			
				|  |  | -      for (let i=1; i<numbers.length; i++){
 | 
	
		
			
				|  |  | -        realRes -= numbers[i]
 | 
	
		
			
				|  |  | +      let realRes = numbers[0];
 | 
	
		
			
				|  |  | +      for(let i=1; i<numbers.length; i++){
 | 
	
		
			
				|  |  | +        realRes -= numbers[i];
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        let afterComma = Math.max(...numbers.map(x => afterCommaLen(x)));
 | 
	
	
		
			
				|  | @@ -112,7 +112,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          addNumbersToTable(numbersArr);
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const handleKeyMoveComma = (e) => {
 | 
	
		
			
				|  |  |      let pressedKey = e.keyCode;
 | 
	
	
		
			
				|  | @@ -143,7 +143,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        let nextFocusId = Math.min(noId+1, numbers.length-1);
 | 
	
		
			
				|  |  |        document.getElementById("numbersTd" + nextFocusId).focus();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const addNumbersToTable = (numbersArr) => {
 | 
	
		
			
				|  |  |      let nos;
 | 
	
	
		
			
				|  | @@ -165,7 +165,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        cell.tabIndex = "0";
 | 
	
		
			
				|  |  |        cell.id = "numbersTd" + noIdx;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const ResultCarryForm = ({handleResChange, handleCarryChange}) => {
 | 
	
		
			
				|  |  |      let resInputField = useRef(null);
 | 
	
	
		
			
				|  | @@ -206,7 +206,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |            if(nosLeft === 1 && (carryArr[0] === "0" || carryArr[0] === "")){
 | 
	
		
			
				|  |  |              nosLeft = 0;
 | 
	
		
			
				|  |  |              imdtResIdx = -1;
 | 
	
		
			
				|  |  | -            return <></>
 | 
	
		
			
				|  |  | +            return <></>;
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |            // create label text like: d + d + (wie viel) = input
 | 
	
	
		
			
				|  | @@ -215,7 +215,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |              digit = 0;
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |            labelText += digit;
 | 
	
		
			
				|  |  | -          if (parseInt(n) === numbers.length - 1){
 | 
	
		
			
				|  |  | +          if(parseInt(n) === numbers.length - 1){
 | 
	
		
			
				|  |  |              if(carryArr[0] !== undefined && carryArr[0] > 0){
 | 
	
		
			
				|  |  |                labelText += " + " + carryArr[0].toString();
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -225,8 +225,8 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      labelText += " + wie viel = " + firstDigit
 | 
	
		
			
				|  |  | -      labelText = labelText.replace(/ /g, "0")
 | 
	
		
			
				|  |  | +      labelText += " + wie viel = " + firstDigit;
 | 
	
		
			
				|  |  | +      labelText = labelText.replace(/ /g, "0");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        imdtResIdx = imdtResIdx - 1;
 | 
	
		
			
				|  |  |        nosLeft = nosLeft - 1;
 | 
	
	
		
			
				|  | @@ -259,12 +259,12 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          </>
 | 
	
		
			
				|  |  |        );
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const addButtonsToImdtSteps = (carryArrCopy) => {
 | 
	
		
			
				|  |  |      // workaround to access DOM td after grid values are set
 | 
	
		
			
				|  |  |      setTimeout(() => {
 | 
	
		
			
				|  |  | -      let table = document.getElementById("idmtResultSteps").getElementsByTagName("table")[0]
 | 
	
		
			
				|  |  | +      let table = document.getElementById("idmtResultSteps").getElementsByTagName("table")[0];
 | 
	
		
			
				|  |  |        let trs = table.getElementsByTagName("tr");
 | 
	
		
			
				|  |  |        for(let trIdx in trs){
 | 
	
		
			
				|  |  |          let tr = trs[trIdx];
 | 
	
	
		
			
				|  | @@ -279,7 +279,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }, 300);
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const showIdmtResults = (carryArrCopy) => {
 | 
	
		
			
				|  |  |      let realResArr = realResult.toString().split("");
 | 
	
	
		
			
				|  | @@ -287,7 +287,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        realResArr.unshift(" "); // add " " before
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    let carries = carryArrCopy.map(x => x || "0")
 | 
	
		
			
				|  |  | +    let carries = carryArrCopy.map(x => x || "0");
 | 
	
		
			
				|  |  |      carries.push("0");
 | 
	
		
			
				|  |  |      while(carries.length < resArr.length){
 | 
	
		
			
				|  |  |        carries.unshift("0"); // add "0" before
 | 
	
	
		
			
				|  | @@ -295,7 +295,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      let foundComma = false;
 | 
	
		
			
				|  |  |      let stepsGridCopy = [];
 | 
	
		
			
				|  |  | -    for (let i=0; i<resArr.length; i++) {
 | 
	
		
			
				|  |  | +    for(let i=0; i<resArr.length; i++) {
 | 
	
		
			
				|  |  |        let text = "";
 | 
	
		
			
				|  |  |        let trueNumbers = false;
 | 
	
		
			
				|  |  |        let idxNumbers = resArr.length - i - 1;
 | 
	
	
		
			
				|  | @@ -312,44 +312,44 @@ function Subtraction() {
 | 
	
		
			
				|  |  |          }else{
 | 
	
		
			
				|  |  |            let no = numbers[j][idxNumbers];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -          if (j === 0){
 | 
	
		
			
				|  |  | +          if(j === 0){
 | 
	
		
			
				|  |  |              realDigitRes = parseInt(no) | 0;
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  | -          else if (no!=="." && no!==" "){
 | 
	
		
			
				|  |  | +          else if(no!=="." && no!==" "){
 | 
	
		
			
				|  |  |              trueNumbers = true;
 | 
	
		
			
				|  |  |              realDigitRes += parseInt(no);
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -          text += no
 | 
	
		
			
				|  |  | -          if (j<numbers.length-1){
 | 
	
		
			
				|  |  | -            text += " + "
 | 
	
		
			
				|  |  | +          text += no;
 | 
	
		
			
				|  |  | +          if(j<numbers.length-1){
 | 
	
		
			
				|  |  | +            text += " + ";
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // ignore indexes without real digits
 | 
	
		
			
				|  |  | -      if (resArr[idxNumbers]!==" " || (carries[idxCarry]!==" " & carries[idxCarry]!=="0")){
 | 
	
		
			
				|  |  | +      if(resArr[idxNumbers]!==" " || (carries[idxCarry]!==" " & carries[idxCarry]!=="0")){
 | 
	
		
			
				|  |  |          trueNumbers = true;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // carry array has no "."
 | 
	
		
			
				|  |  | -      if (resArr[idxNumbers] === "."){
 | 
	
		
			
				|  |  | +      if(resArr[idxNumbers] === "."){
 | 
	
		
			
				|  |  |          foundComma = true;
 | 
	
		
			
				|  |  |          trueNumbers = false;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      if (foundComma){
 | 
	
		
			
				|  |  | +      if(foundComma){
 | 
	
		
			
				|  |  |          idxCarry += 1;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // add carry only if > 0
 | 
	
		
			
				|  |  | -      if (carries[idxCarry]!=="0"){
 | 
	
		
			
				|  |  | +      if(carries[idxCarry]!=="0"){
 | 
	
		
			
				|  |  |          realDigitRes += parseInt(carries[idxCarry]);
 | 
	
		
			
				|  |  | -        text += " + " + carries[idxCarry] // + " Übertrag"
 | 
	
		
			
				|  |  | +        text += " + " + carries[idxCarry]; // + " Übertrag"
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        let realCarry = Math.abs(parseInt(realDigitRes/10));
 | 
	
		
			
				|  |  |        realDigitRes = ((firstDigit - realDigitRes) % 10);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      if (realDigitRes < 0){
 | 
	
		
			
				|  |  | +      if(realDigitRes < 0){
 | 
	
		
			
				|  |  |          realDigitRes = realDigitRes + 10;
 | 
	
		
			
				|  |  |          realCarry += 1;
 | 
	
		
			
				|  |  |        }
 | 
	
	
		
			
				|  | @@ -358,16 +358,16 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        realDigitRes = realDigitRes.toString();
 | 
	
		
			
				|  |  |        text += " und ";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      if (trueNumbers){
 | 
	
		
			
				|  |  | -        text += resArr[idxNumbers] + " = " + firstDigit
 | 
	
		
			
				|  |  | -        text += " mit Übertrag " + carries[idxCarry-1]
 | 
	
		
			
				|  |  | -        text = text.replace(/ /g, "0")
 | 
	
		
			
				|  |  | +      if(trueNumbers){
 | 
	
		
			
				|  |  | +        text += resArr[idxNumbers] + " = " + firstDigit;
 | 
	
		
			
				|  |  | +        text += " mit Übertrag " + carries[idxCarry-1];
 | 
	
		
			
				|  |  | +        text = text.replace(/ /g, "0");
 | 
	
		
			
				|  |  |          text += resArr[idxNumbers]===realDigitRes && carries[idxCarry-1]===realCarry ? ": Richtig " : ": Falsch ";
 | 
	
		
			
				|  |  |          stepsGridCopy.push({step: text});
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    let paragraph = document.getElementById("stepsParagraph")
 | 
	
		
			
				|  |  | +    let paragraph = document.getElementById("stepsParagraph");
 | 
	
		
			
				|  |  |      paragraph.innerHTML = "Rechenschritte: ";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      let btnSubmit = document.createElement("button");
 | 
	
	
		
			
				|  | @@ -389,7 +389,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |      document.getElementById("idmtResultSteps").style.display = "inline-block";
 | 
	
		
			
				|  |  |      document.getElementById("idmtResultSteps").tabIndex = 0;
 | 
	
		
			
				|  |  |      document.getElementById("idmtResultSteps").focus();
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const startOver = (idx, carryArrCopy) => {
 | 
	
		
			
				|  |  |      let invertedIdx = numbers[0].length - idx - 1;
 | 
	
	
		
			
				|  | @@ -417,7 +417,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |      document.getElementById("btnSubmitSteps1").remove();
 | 
	
		
			
				|  |  |      document.getElementById("btnSubmitSteps2").remove();
 | 
	
		
			
				|  |  |      document.getElementById("idmtResultSteps").style.display = "none";
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const finishCalculation = () => {
 | 
	
		
			
				|  |  |      document.getElementById("idmtResultSteps").innerHTML = "";
 | 
	
	
		
			
				|  | @@ -428,11 +428,11 @@ function Subtraction() {
 | 
	
		
			
				|  |  |      for(let r in resArr){
 | 
	
		
			
				|  |  |        let digit = resArr[r];
 | 
	
		
			
				|  |  |        if(digit===" "){
 | 
	
		
			
				|  |  | -        continue
 | 
	
		
			
				|  |  | +        continue;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        if(digit!=="0" | beginNr | parseInt(r)===resArr.length-1){
 | 
	
		
			
				|  |  |          beginNr = true;
 | 
	
		
			
				|  |  | -        res.push(digit)
 | 
	
		
			
				|  |  | +        res.push(digit);
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      let resCalc = res.join("");
 | 
	
	
		
			
				|  | @@ -452,14 +452,14 @@ function Subtraction() {
 | 
	
		
			
				|  |  |      document.getElementById("finishCalculation").innerHTML = message;
 | 
	
		
			
				|  |  |      document.getElementById("finishCalculation").tabIndex = "0";
 | 
	
		
			
				|  |  |      document.getElementById("finishCalculation").focus();
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const startCommaMove = () => {
 | 
	
		
			
				|  |  |      document.getElementById("commaSubmit").style.display = "inline-block";
 | 
	
		
			
				|  |  |      setTimeout(() => {
 | 
	
		
			
				|  |  |        document.getElementById("numbersTd0").focus();
 | 
	
		
			
				|  |  | -    }, 300)
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +    }, 300);
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const submitCommaMove = () => {
 | 
	
		
			
				|  |  |      let numbersCopy = [...numbers];
 | 
	
	
		
			
				|  | @@ -489,7 +489,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |      if(commaPositions.length === 0){
 | 
	
		
			
				|  |  |        setCommaIdx(-1);
 | 
	
		
			
				|  |  |        // check if no number was moved
 | 
	
		
			
				|  |  | -      commaCorrect = !numbersCopy.map(n => n[numbersLen] !== " ").includes(false)
 | 
	
		
			
				|  |  | +      commaCorrect = !numbersCopy.map(n => n[numbersLen] !== " ").includes(false);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // correct comma positions
 | 
	
		
			
				|  |  |      }else if(commaPositions.length === 1){
 | 
	
	
		
			
				|  | @@ -522,7 +522,7 @@ function Subtraction() {
 | 
	
		
			
				|  |  |        paragraph.tabIndex = "0";
 | 
	
		
			
				|  |  |        paragraph.focus();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    return (
 | 
	
		
			
				|  |  |      <main>
 |