From 98092ee43f6da477502ed763f679c7d0d40b65fc Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Mon, 18 Jun 2018 15:57:45 +0300 Subject: [PATCH] Code style fixes. --- src/algorithms/sets/knapsack-problem/Knapsack.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/algorithms/sets/knapsack-problem/Knapsack.js b/src/algorithms/sets/knapsack-problem/Knapsack.js index 10ce6334..90858957 100644 --- a/src/algorithms/sets/knapsack-problem/Knapsack.js +++ b/src/algorithms/sets/knapsack-problem/Knapsack.js @@ -166,12 +166,16 @@ export default class Knapsack { const maxPossibleItemsCount = Math.floor(availableWeight / currentItem.weight); if (maxPossibleItemsCount > currentItem.itemsInStock) { + // If we have more items in stock then it is allowed to add + // let's add the maximum allowed number of them. currentItem.quantity = currentItem.itemsInStock; - this.selectedItems.push(currentItem); } else if (maxPossibleItemsCount) { + // In case if we don't have specified number of items in stock + // let's add only items we have in stock. currentItem.quantity = maxPossibleItemsCount; - this.selectedItems.push(currentItem); } + + this.selectedItems.push(currentItem); } } }