我为此创建了一个函数。也许存在更好的解决方案?
function writeLog(operationIdentifier, prevResult, operationNumber, newResult) {
const logEntry = {
operation: operationIdentifier,
prevResult: prevResult,
number: operationNumber,
result: newResult,
};
logEntries.push(logEntry);
console.log(logEntries);
由此:
function add() {
const enteredNumber = getUserNumberInput();
const initialResult = currentResult;
currentResult += enteredNumber;
createAndWriteOutput('+', initialResult, enteredNumber);
writeLog('ADD', initialResult, enteredNumber, currentResult);
}
达令说
相关分类