Skip to content

Commit 98092ee

Browse files
committed
Code style fixes.
1 parent 8c206a9 commit 98092ee

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/algorithms/sets/knapsack-problem/Knapsack.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,16 @@ export default class Knapsack {
166166
const maxPossibleItemsCount = Math.floor(availableWeight / currentItem.weight);
167167

168168
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.
169171
currentItem.quantity = currentItem.itemsInStock;
170-
this.selectedItems.push(currentItem);
171172
} 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.
172175
currentItem.quantity = maxPossibleItemsCount;
173-
this.selectedItems.push(currentItem);
174176
}
177+
178+
this.selectedItems.push(currentItem);
175179
}
176180
}
177181
}

0 commit comments

Comments
 (0)