{
  "id": 21336123,
  "title": "Hai lần giảm giá liên tiếp trong JavaScript: kiểm thử bằng số nguyên",
  "url": "https://urgent.news/2026/11/23/hai-lan-giam-gia-lien-tiep-trong-javascript-kiem-thu-bang-so-nguyen",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-23T03:28:21.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/gia_ssv_69530693b7ff92c/hai-lan-giam-gia-lien-tiep-trong-javascript-kiem-thu-bang-so-nguyen-1262"
  },
  "original_language": "en",
  "account": "When practicing JavaScript percentage calculations, a common mistake is to add two discounts before computing the final value. For example, applying a 25% reduction followed by an additional 20% discount reduces a price of 100 to 75, then to 60. The second discount is calculated on the reduced 75, making the total discount 40%. Write a one-step function To test, the function accepts an amount expressed in the smallest unit (such as cents), and a whole number percentage ranging from 0 to 100. Using small integers keeps the focus on order of operations and rounding rules. Import the assert module for testing. Define the afterDiscount function to calculate the discounted amount. Set a starting amount of 10,000 cents. Call the function twice, first with a 25% discount, then a 20% discount on the result. Assert that the intermediate and final amounts match the expected values of 7,500 and 6,000 cents, respectively. Verify that applying no discount leaves the amount unchanged. Assert that a 100% discount reduces any amount to zero. Check that applying a discount twice does not change the amount if the second discount is 10% of the already discounted value. To validate rounding, test the scenario where a price of 5 cents is discounted twice by 10%. The rule requires the final result to remain 5 cents. If an odd number is retained, multiplying 5 by 0.9 twice results in 4.05 cents, which should round to 4 cents. Different rounding rules apply in real-world applications. Determine which rule to follow and test the input range. This article was written with AI assistance.",
  "summary": "Khi viết bài tập JavaScript về phần trăm, một lỗi thường gặp là cộng hai mức giảm trước khi tính. Ví dụ, giảm 25% rồi giảm thêm 20% khiến giá từ 100 xuống 75, rồi từ 75 xuống 60. Mức giảm thứ hai tính trên 75, vì vậy tổng mức giảm là 40%. Viết hàm xử lý một bước Hàm nhận số tiền đã quy đổi sang đơn vị nhỏ nhất, chẳng hạn cent, và phần trăm nguyên từ 0 đến 100. Ví dụ dùng các số nguyên nhỏ, đủ để…",
  "key_points": [
    "Function accepts amount in cents and percentage discount",
    "Apply one-step function to calculate final discounted amount",
    "Assert intermediate and final amounts match expected values"
  ],
  "editors_take": "Using small integer units for percentage calculations shifts the focus from floating-point errors to the critical logic of order of operations and specific rounding rules in financial programming.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}