Merged Result
function calculateTotal(items) {
let total = 0;
for (let item of items) {
total += item.price;
}
return total;
}
function calculateTotalWithTax(items, taxRate = 0.08) {
const subtotal = calculateTotal(items);
const tax = subtotal * taxRate;
return {
subtotal,
tax,
total: subtotal + tax
};
}
// Export for use in other modules
module.exports = {
calculateTotal,
calculateTotalWithTax
};