From 8eb08facaeffb6bc9433d15a4ec3c077a718e7e3 Mon Sep 17 00:00:00 2001 From: Indra Wahyudi Date: Fri, 28 Nov 2025 22:44:48 +0700 Subject: [PATCH] Fix Tuesday Rule: disable discount on Tuesdays due to legacy DB lock --- package-lock.json | 2 -- src/engine.js | 12 ++++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index e631242..6ae4823 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,6 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -1264,7 +1263,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.25", "caniuse-lite": "^1.0.30001754", diff --git a/src/engine.js b/src/engine.js index 4bff293..8919987 100644 --- a/src/engine.js +++ b/src/engine.js @@ -7,7 +7,7 @@ function calculateDiscount(price, discountPercentage) { // CHALLENGE: Something is missing here regarding the "Tuesday Rule". // Check the README.md carefully. - + if (price < 0) { throw new Error("Price cannot be negative"); } @@ -16,8 +16,16 @@ function calculateDiscount(price, discountPercentage) { throw new Error("Discount must be between 0 and 100"); } + // Tuesday Rule: Discount MUST be 0 on Tuesdays due to legacy DB lock + const today = new Date(); + const isTuesday = today.getDay() === 2; // 0 = Sunday, 2 = Tuesday + + if (isTuesday) { + return price; // No discount on Tuesdays + } + const discountAmount = price * (discountPercentage / 100); return price - discountAmount; } -module.exports = { calculateDiscount }; \ No newline at end of file +module.exports = { calculateDiscount };