Initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const LinkedList = require("../Utility/LinkedList");
|
||||
|
||||
class LinkedListNode {
|
||||
constructor(key, value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.next = null;
|
||||
};
|
||||
};
|
||||
|
||||
class InventoryList extends LinkedList {
|
||||
constructor() {
|
||||
super();
|
||||
};
|
||||
|
||||
accumulateItem(key, value) {
|
||||
const entry = this.map.get(key);
|
||||
const updatedValue = entry ? entry.value.amount + value.amount : value;
|
||||
|
||||
if (entry) entry.value.amount = updatedValue;
|
||||
else this.addItem(key, updatedValue); /// eeeh
|
||||
}
|
||||
|
||||
addItem(key, value) {
|
||||
if (!key || !value || !value.categoryID || !value.id || isNaN(value.amount)) return console.info("addItem", key, value);
|
||||
|
||||
const temp = new LinkedListNode(key, value);
|
||||
|
||||
if (!this.head) {
|
||||
this.head = temp;
|
||||
this.tail = temp;
|
||||
} else {
|
||||
this.tail.next = temp;
|
||||
this.tail = temp;
|
||||
};
|
||||
|
||||
this.map.set(key, temp);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = InventoryList;
|
||||
Reference in New Issue
Block a user