File tree 1 file changed +6
-2
lines changed
src/algorithms/sets/knapsack-problem
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -166,12 +166,16 @@ export default class Knapsack {
166
166
const maxPossibleItemsCount = Math . floor ( availableWeight / currentItem . weight ) ;
167
167
168
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.
169
171
currentItem . quantity = currentItem . itemsInStock ;
170
- this . selectedItems . push ( currentItem ) ;
171
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.
172
175
currentItem . quantity = maxPossibleItemsCount ;
173
- this . selectedItems . push ( currentItem ) ;
174
176
}
177
+
178
+ this . selectedItems . push ( currentItem ) ;
175
179
}
176
180
}
177
181
}
You can’t perform that action at this time.
0 commit comments