We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8c206a9 commit 98092eeCopy full SHA for 98092ee
src/algorithms/sets/knapsack-problem/Knapsack.js
@@ -166,12 +166,16 @@ export default class Knapsack {
166
const maxPossibleItemsCount = Math.floor(availableWeight / currentItem.weight);
167
168
if (maxPossibleItemsCount > currentItem.itemsInStock) {
169
+ // If we have more items in stock then it is allowed to add
170
+ // let's add the maximum allowed number of them.
171
currentItem.quantity = currentItem.itemsInStock;
- this.selectedItems.push(currentItem);
172
} else if (maxPossibleItemsCount) {
173
+ // In case if we don't have specified number of items in stock
174
+ // let's add only items we have in stock.
175
currentItem.quantity = maxPossibleItemsCount;
176
}
177
+
178
+ this.selectedItems.push(currentItem);
179
180
181
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments