mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Upgrade packages.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user