mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-27 15:41:16 +08:00
Code style fixes.
This commit is contained in:
parent
8c206a9976
commit
98092ee43f
@ -166,12 +166,16 @@ export default class Knapsack {
|
|||||||
const maxPossibleItemsCount = Math.floor(availableWeight / currentItem.weight);
|
const maxPossibleItemsCount = Math.floor(availableWeight / currentItem.weight);
|
||||||
|
|
||||||
if (maxPossibleItemsCount > currentItem.itemsInStock) {
|
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;
|
currentItem.quantity = currentItem.itemsInStock;
|
||||||
this.selectedItems.push(currentItem);
|
|
||||||
} else if (maxPossibleItemsCount) {
|
} 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;
|
currentItem.quantity = maxPossibleItemsCount;
|
||||||
this.selectedItems.push(currentItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.selectedItems.push(currentItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user