Change:
# --solutions-- ```js <del> function knapsackUnbounded(items, maxweight, maxvolume) { var n = items.length; var best_value = 0; var count = new Array(n); var best = new Array(n); function recurseKnapsack(i, value, weight, volume) { var j, m1, m2, m; if (i == n) { if (value > best_value) { best_value = value; for (j = 0; j < n; j++) { best[j] = count[j]; } } return; </del> <ins> function knapsackUnbounded(items, maxWeight, maxVolume) { function getPickTotals(items, pick) { let totalValue = 0; let totalWeight = 0; let totalVolume = 0; for (let i = 0; i < items.length; i++) { totalValue += pick[i] * items[i].value; totalWeight += pick[i] * items[i].weight; totalVolume += pick[i] * items[i].volume; } return [totalValue, totalWeight, totalVolume]; } function getMaxes(items, maxWeight, maxVolume) { const maxes = []; for (let i = 0; i < items.length; i++) { const maxUnitsInWeight = Math.floor(maxWeight / items[i].weight); const maxUnitsInVolume = Math.floor(maxVolume / items[i].volume); const maxUnitsInLimit = Math.min(maxUnitsInWeight, maxUnitsInVolume); maxes.push(maxUnitsInLimit); </ins> } <del> m1 = Math.floor(weight / items[i].weight); m2 = Math.floor(volume / items[i].volume); m = m1 < m2 ? m1 : m2; for (count[i] = m; count[i] >= 0; count[i]--) { recurseKnapsack( i + 1, value + count[i] * items[i].value, weight - count[i] * items[i].weight, volume - count[i] * items[i].volume ); </del> <ins> return maxes; } function isInLimit(value, limit) { return value <= limit; } function getCombinations(maxValues, curPicks, combinations) { if (maxValues.length === 0) { combinations.push(curPicks); } const curMax = maxValues[0]; const leftMaxValues = maxValues.slice(1); for (let i = 0; i <= curMax; i++) { getCombinations(leftMaxValues, curPicks.concat(i), combinations); } return combinations; } let bestValue = 0; let bestPick = []; const maxes = getMaxes(items, maxWeight, maxVolume); const combinations = getCombinations(maxes, [], []); for (let i = 0; i < combinations.length; i++) { const curPick = combinations[i]; const [curValue, curWeight, curVolume] = getPickTotals(items, curPick); if (!isInLimit(curWeight, maxWeight) || !isInLimit(curVolume, maxVolume)) { continue; } if (curValue > bestValue) { bestValue = curValue; bestPick = [curPick]; } else if (curValue === bestValue) { bestPick.push(curPick); </ins> } } <del> recurseKnapsack(0, 0, maxweight, maxvolume); return best_value; </del> <ins> return bestValue; </ins> } ```

Discussion:
Describe your problem and how to reproduce it: One of the tests in this challenge has wrong result, both in test code and description. It says: This isn't correct. For example: knapsack having 11 panacea, 3 ichor and 15 gold has value , while being within the weight and value constrains: This seems to be case of precision issue. Multiplication input item weights, volumes and max values for those parameters, to start operations without decimals, makes result as it should be, also for the problematic test. Add a Link to the page with the problem:
Yes, it seems you are right - do you want to propose a solution?
Yes, sorry. The least invasive way to correct the seems to be to multiply in function, by the same factor, initial items weights, volumes, and in the first recursive call multiply and . This is enough to make calculations on integers and get correct answers. I don't know if just such change would be okay or if more desirable would be more elaborate rewrite of solution. Or at least changing to / and renaming some variables to better names.
would you be willing to open a PR for it so that the challenge can be changed? you can also contribute to the guide by opening a topic in the #subforum category in the forum
Definitely yes, although I need advice which approach here would be preferred. Considering that the sample solution in code is just used for internal testing and just small change to it can fix the issue.