chore: add comment on makeChange function to inform of possible drawbacks

This commit is contained in:
Sérgio Salgado 2021-09-07 17:20:34 +01:00
parent 9d4d933f05
commit a3711be533

View file

@ -11,6 +11,11 @@ exports.makeChange = function makeChange (cassettes, amount) {
// Note: Everything here is converted to primitive numbers, // Note: Everything here is converted to primitive numbers,
// since they're all integers, well within JS number range, // since they're all integers, well within JS number range,
// and this is way more efficient in a tight loop. // and this is way more efficient in a tight loop.
// Another note: While this greedy algorithm possibly works for all major denominations,
// it still requires a fallback for cases where it might not provide any solution.
// Example: Denominations: [3, 5, 10] | User inputs 4 times the [3] button, resulting in a 12 fiat tx
// This algorithm resolves for 1 x [10], and can't resolve the remainder of 2
const cassetteMap = _.map(cassettes, it => ({ const cassetteMap = _.map(cassettes, it => ({
denomination: it.denomination denomination: it.denomination
})) }))