File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
src/algorithms/sets/knapsack-problem Expand file tree Collapse file tree 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 {
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 }
You can’t perform that action at this time.
0 commit comments