|
@@ -48,12 +48,9 @@ function Addition() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const handleCarryChange = (e, noOfDigits, idx, nosLeft) => {
|
|
|
- if(typeof carryArr === "undefined"){
|
|
|
- setCarryArr(Array(noOfDigits).fill("-"));
|
|
|
- }
|
|
|
+ const handleCarryChange = (e, noOfDigits, nosLeft) => {
|
|
|
let carryArrCopy = [...carryArr]
|
|
|
- carryArrCopy[idx] = e.target.value
|
|
|
+ carryArrCopy.unshift(e.target.value);
|
|
|
setCarryArr(carryArrCopy);
|
|
|
let noCarry = carryArrCopy[0] === "0" || carryArrCopy[0] === undefined
|
|
|
if(nosLeft === 0 || (nosLeft === 1 && noCarry) ||
|
|
@@ -87,17 +84,16 @@ function Addition() {
|
|
|
let labelText = "";
|
|
|
let nosLeft = imdtResIdx + 1;
|
|
|
let carryText = "Übertrag = ";
|
|
|
- let carryOffset = 0;
|
|
|
|
|
|
if(typeof numbers === "object" && imdtResIdx !== -1){
|
|
|
if(typeof imdtResIdx === "undefined" || imdtResIdx === null){
|
|
|
noOfDigits = Math.min(...numbers.map(n => n.length));
|
|
|
imdtResIdx = noOfDigits-1;
|
|
|
}
|
|
|
+
|
|
|
if(imdtResIdx === commaIdx){
|
|
|
handleResChange(".", nosLeft)
|
|
|
imdtResIdx = imdtResIdx - 1;
|
|
|
- carryOffset = 1;
|
|
|
nosLeft = nosLeft - 1;
|
|
|
}
|
|
|
|
|
@@ -115,8 +111,8 @@ function Addition() {
|
|
|
labelText += digit;
|
|
|
|
|
|
if (parseInt(n) === numbers.length - 1){
|
|
|
- if(carryArr[imdtResIdx+carryOffset]!=="undefind" && carryArr[imdtResIdx+carryOffset] > 0){
|
|
|
- labelText += " + " + carryArr[imdtResIdx+carryOffset].toString();
|
|
|
+ if(carryArr[0]!=="undefind" && carryArr[0] > 0){
|
|
|
+ labelText += " + " + carryArr[0].toString();
|
|
|
}
|
|
|
labelText += " = ";
|
|
|
}else{
|
|
@@ -124,7 +120,7 @@ function Addition() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(carryArr[imdtResIdx+carryOffset] > -1 || imdtResIdx === noOfDigits-1){
|
|
|
+ if(carryArr[0] > -1 || imdtResIdx === noOfDigits-1){
|
|
|
imdtRes = -1;
|
|
|
imdtResIdx = imdtResIdx - 1;
|
|
|
nosLeft = nosLeft - 1;
|
|
@@ -145,7 +141,7 @@ function Addition() {
|
|
|
{carryText}
|
|
|
</label>
|
|
|
<input
|
|
|
- onChange={(e) => handleCarryChange(e, noOfDigits, imdtResIdx, nosLeft)}
|
|
|
+ onChange={(e) => handleCarryChange(e, noOfDigits, nosLeft)}
|
|
|
type="text" id="input_carry" size="2"
|
|
|
aria-labelledby="input_carry_label" aria-required="true"
|
|
|
ref={carryInputField}/>
|
|
@@ -174,7 +170,7 @@ function Addition() {
|
|
|
|
|
|
let foundComma = false;
|
|
|
let stepsGridCopy = [];
|
|
|
- for (let i=0; i<resArr.length-1; i++) {
|
|
|
+ for (let i=0; i<resArr.length; i++) {
|
|
|
let text = "";
|
|
|
let trueNumbers = false;
|
|
|
let idxNumbers = resArr.length - i - 1;
|
|
@@ -193,7 +189,7 @@ function Addition() {
|
|
|
}
|
|
|
|
|
|
// ignore indexes without real digits
|
|
|
- if (resArr[idxNumbers]!==" " || carries[idxCarry]!==" "){
|
|
|
+ if (resArr[idxNumbers]!==" " || (carries[idxCarry]!==" " & carries[idxCarry]!=="0")){
|
|
|
trueNumbers = true;
|
|
|
}
|
|
|
|