Ai
1 Star 0 Fork 81

zhizou/javascript-algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
KnapsackItem.js 938 Bytes
一键复制 编辑 原始数据 按行查看 历史
Oleksii Trekhleb 提交于 2018-04-30 19:08 +08:00 . Add knapsack problem.
export default class KnapsackItem {
/**
* @param {Object} itemSettings - knapsack item settings,
* @param {number} itemSettings.value - value of the item.
* @param {number} itemSettings.weight - weight of the item.
* @param {number} itemSettings.itemsInStock - how many items are available to be added.
*/
constructor({ value, weight, itemsInStock = 1 }) {
this.value = value;
this.weight = weight;
this.itemsInStock = itemsInStock;
// Actual number of items that is going to be added to knapsack.
this.quantity = 1;
}
get totalValue() {
return this.value * this.quantity;
}
get totalWeight() {
return this.weight * this.quantity;
}
// This coefficient shows how valuable the 1 unit of weight is
// for current item.
get valuePerWeightRatio() {
return this.value / this.weight;
}
toString() {
return `v${this.value} w${this.weight} x ${this.quantity}`;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhizous/javascript-algorithms.git
git@gitee.com:zhizous/javascript-algorithms.git
zhizous
javascript-algorithms
javascript-algorithms
master

搜索帮助