From 9ef9a70c39cf097219eb8c8e5ea9b661562b356e Mon Sep 17 00:00:00 2001 From: siiky Date: Mon, 3 Feb 2025 14:36:30 +0000 Subject: [PATCH] fix: use the same solution format for `subset-sum` as for `coin-change` --- lib/bill-math.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/bill-math.js b/lib/bill-math.js index b093fd46..8d4515c2 100644 --- a/lib/bill-math.js +++ b/lib/bill-math.js @@ -116,14 +116,8 @@ const getSolution_old = (units, amount, mode) => { const solver = sumService.subsetSum(billList, amount.toNumber()) const solution = _.countBy(Math.floor, solver.next().value) - return _.reduce( - (acc, value) => { - acc.push({ denomination: _.toNumber(value), provisioned: solution[value] }) - return acc - }, - [], - _.keys(solution) - ) + return Object.entries(solution) + .map(([denomination, provisioned]) => [_.toNumber(denomination), provisioned]) } const getSolution = (units, amount) => {