From 681b76739f6dc6efe859e713b5eb3e84ea60cee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 13 Jan 2022 17:42:22 +0000 Subject: [PATCH] fix: initialize empty cassettes in case of undefined values --- lib/bill-math.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/bill-math.js b/lib/bill-math.js index d4801c0f..fbb3ee99 100644 --- a/lib/bill-math.js +++ b/lib/bill-math.js @@ -73,8 +73,9 @@ function unmergeCassettes(cassettes, output) { } function makeChangeDuo(cassettes, amount) { - const small = cassettes[0] - const large = cassettes[1] + // Initialize empty cassettes in case of undefined, due to same denomination across all cassettes results in a single merged cassette + const small = cassettes[0] ?? { denomination: 0, count: 0 } + const large = cassettes[1] ?? { denomination: 0, count: 0 } const largeDenom = large.denomination const smallDenom = small.denomination