Merge pull request #1921 from RafaelTaranto/fix/coin-change-with-empty-box
LAM-1496 fix: coin change with empty box
This commit is contained in:
commit
bc4d41951a
1 changed files with 3 additions and 3 deletions
|
|
@ -9,12 +9,12 @@
|
|||
*/
|
||||
const prepare_denominations = denominations =>
|
||||
JSON.parse(JSON.stringify(denominations))
|
||||
.sort(([d1], [d2]) => d2 - d1)
|
||||
.filter(([, count]) => count > 0)
|
||||
.sort(([d1], [d2]) => d1 - d2)
|
||||
.reduce(
|
||||
([csum, denoms], [denom, count]) => {
|
||||
csum += denom * count
|
||||
denoms.push({ denom, count, csum })
|
||||
return [csum, denoms]
|
||||
return [csum, [{ denom, count, csum }].concat(denoms)]
|
||||
},
|
||||
[0, []],
|
||||
)[1] /* ([csum, denoms]) => denoms */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue