// ฟังก์ชันคำนวณยอดเงินคงเหลือ
function calculateBalance(deposit, withdraw, previousBalance) {
return previousBalance + deposit - withdraw;
}
// ฟังก์ชันที่เรียกใช้งาน
function processTransaction(transaction) {
const deposit = transaction.deposit || 0;
const withdraw = transaction.withdraw || 0;
const previousBalance = transaction.previousBalance || 0;
const newBalance = calculateBalance(deposit, withdraw, previousBalance);
return {
…transaction,
balance: newBalance
};
}