|
@@ -132,14 +132,18 @@ function Subtraction() {
|
|
|
let numbersCopy = [...numbers];
|
|
|
|
|
|
if(pressedKey === 37){ // left arrow
|
|
|
- numbersCopy[noId].push(" ");
|
|
|
+ if(numbersCopy[noId].includes(".")){
|
|
|
+ numbersCopy[noId].push("0");
|
|
|
+ }else{
|
|
|
+ numbersCopy[noId].push(".");
|
|
|
+ }
|
|
|
setNumbers(numbersCopy);
|
|
|
setTimeout(() => {
|
|
|
document.getElementById(tdId).focus();
|
|
|
}, 100);
|
|
|
|
|
|
}else if(pressedKey === 39 && // right arrow
|
|
|
- numbersCopy[noId][numbersCopy[noId].length-1] === " "){
|
|
|
+ [".", "0"].includes(numbersCopy[noId][numbersCopy[noId].length-1])){
|
|
|
numbersCopy[noId].pop();
|
|
|
setNumbers(numbersCopy);
|
|
|
setTimeout(() => {
|
|
@@ -225,7 +229,7 @@ function Subtraction() {
|
|
|
|
|
|
// create label text like: d + d + (wie viel) = input
|
|
|
digit = numbers[parseInt(n)][imdtResIdx];
|
|
|
- if(digit === "" || digit === " "){
|
|
|
+ if([".", "0", " ", ""].includes(digit)){
|
|
|
digit = 0;
|
|
|
}
|
|
|
labelText += digit;
|
|
@@ -500,34 +504,12 @@ function Subtraction() {
|
|
|
setNumbers(numbersCopy);
|
|
|
|
|
|
let commaCorrect = false;
|
|
|
- commaPositions = [...new Set(commaPositions.filter(c => c >= 0))];
|
|
|
+ commaPositions = [...new Set(commaPositions)];
|
|
|
|
|
|
// if no commas in numbers
|
|
|
- if(commaPositions.length === 0){
|
|
|
- setCommaIdx(-1);
|
|
|
- // check if no number was moved
|
|
|
- commaCorrect = !numbersCopy.map(n => n[numbersLen] !== " ").includes(false);
|
|
|
-
|
|
|
- // correct comma positions
|
|
|
- }else if(commaPositions.length === 1){
|
|
|
+ if(commaPositions.length === 1 && commaPositions[0] !== numbersLen){
|
|
|
setCommaIdx(commaPositions[0]);
|
|
|
commaCorrect = true;
|
|
|
-
|
|
|
- // check if numbers without comma are correct too
|
|
|
- for(let no of numbersCopy){
|
|
|
- if(!no.includes(".")){
|
|
|
- // digit before comma is a number, no space
|
|
|
- if(no[commaPositions[0]-1] === " "){
|
|
|
- commaCorrect = false;
|
|
|
- }
|
|
|
- // only spaces from comma to end
|
|
|
- for(let digit=commaPositions[0]; digit<=numbersLen; digit++){
|
|
|
- if(no[digit] !== " "){
|
|
|
- commaCorrect = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
if(commaCorrect){
|