fix: use the same solution format for subset-sum as for coin-change

This commit is contained in:
siiky 2025-02-03 14:36:30 +00:00
parent 91c4ca4dce
commit 9ef9a70c39

View file

@ -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) => {