@@ -152,10 +179,12 @@ const HwGen = (() => {
}
const { title, count, columns, xSize, ySize, mathSymbol, myGenEqList, outputFunc, answerKey, long, answerSpace, useAllPossible1Digit, myGenEq } = hwSet;
worksheetsDiv.innerHTML = "";
+ // Only apply borrowing filter for subtraction problems
+ const onlyBorrowing = data['onlyBorrowing'] && data['selectedCat'] === 'Subtraction';
for (let i = 0; i < data['selectedCount']; i++) {
const worksheet = worksheetOrig.cloneNode(true)
, output = worksheet.querySelector(".output")
- , eqList = myGenEqList ? myGenEqList() : generate(xSize, ySize, mathSymbol, count, useAllPossible1Digit, myGenEq)
+ , eqList = myGenEqList ? myGenEqList() : generate(xSize, ySize, mathSymbol, count, useAllPossible1Digit, myGenEq, onlyBorrowing)
, titleDiv = worksheet.querySelector(".title")
, outputStr = eqList.map((eq, i) => outputFunc(eq, i, columns, long, answerSpace)).join("")
, emoji = randArr(emojis)
@@ -206,6 +235,7 @@ const HwGen = (() => {
}
data['selectedCount'] = worksheetCountSelect ? parseInt(worksheetCountSelect.value) : 1;
data['showAnswerKey'] = answerKeyChkbx.checked ? true : false;
+ data['onlyBorrowing'] = borrowingChkbx && borrowingChkbx.checked ? true : false;
};
const init = () => {
const hwSetName = getUrlParam("set");
diff --git a/src/js/util.js b/src/js/util.js
index 293c41c..324efcd 100644
--- a/src/js/util.js
+++ b/src/js/util.js
@@ -24,6 +24,20 @@ const solution = (x, y, mathSymbol) => {
default: return x + y;
}
};
+const requiresBorrowing = (minuend, subtrahend) => {
+ const minuendStr = String(minuend);
+ const subtrahendStr = String(subtrahend);
+ const maxLen = Math.max(minuendStr.length, subtrahendStr.length);
+
+ for (let i = 0; i < maxLen; i++) {
+ const minuendDigit = parseInt(minuendStr[minuendStr.length - 1 - i] || 0);
+ const subtrahendDigit = parseInt(subtrahendStr[subtrahendStr.length - 1 - i] || 0);
+ if (minuendDigit < subtrahendDigit) {
+ return true;
+ }
+ }
+ return false;
+};
const getUrlParam = param => {
const paramMap = {};
const urlArr = document.location.href.split("?");