Upgrade packages.

This commit is contained in:
Oleksii Trekhleb
2018-07-05 16:30:00 +03:00
parent 58640ee7b5
commit 17ad4dc4d1
14 changed files with 1695 additions and 542 deletions

View File

@@ -128,16 +128,16 @@ export default class Knapsack {
// In this case this would mean that we need to include previous item
// to the list of selected items.
if (
knapsackMatrix[itemIndex][weightIndex] &&
knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
knapsackMatrix[itemIndex][weightIndex]
&& knapsackMatrix[itemIndex][weightIndex] === knapsackMatrix[itemIndex - 1][weightIndex]
) {
// Check if there are several items with the same weight but with the different values.
// We need to add highest item in the matrix that is possible to get the highest value.
const prevSumValue = knapsackMatrix[itemIndex - 1][weightIndex];
const prevPrevSumValue = knapsackMatrix[itemIndex - 2][weightIndex];
if (
!prevSumValue ||
(prevSumValue && prevPrevSumValue !== prevSumValue)
!prevSumValue
|| (prevSumValue && prevPrevSumValue !== prevSumValue)
) {
this.selectedItems.push(prevItem);
}