This is building a node.js module that is designed to track inventoru for a stor
ID: 3805346 • Letter: T
Question
This is building a node.js module that is designed to track inventoru for a store. JavaScript, I need it as code.
I need the inventory that exposes the following functionality:
1. addItem - A function that takes 2 parameters: an item's name and price and tracks it internally.
2. items - A function that returns a list of items, sorted by price from least expensive to most expensive.
3. getMostExpensive - Returns an object that contains the item's name and price for the most expensive item that has been added.
4. getLeastExpensive - Returns an object that contains the item's name and price for the most least expensive item that has been added.
5. removeItem - Remove an item by name.
6. getItemByName - Returns an item's name and price by name.
7. getItemByPrice - Returns an item's name and price by price.
The module should not expose any functions or bariables that would allow the above functions to have the integrityof their data compromised.
Explanation / Answer
var inventory=Array("item","price");
var item=10;
var price=10;
function start()
{
print(inventory);
}
function additem()
{
if(input.GetMouse.buttondown(0))
{
if("item" in inventory)
{
item+=5;
inventory.add("item");
print (inventory);
}
if("price" in inventory)
{
price+=6;
inventory.add("price");
print(inventory);
}
}
}
function update()
{
if(input.GetMouse.buttondown(0))
{
if("item" in inventory)
{
item+=2;
inventory.Remove("item");
print (inventory);
}
if("price" in inventory)
{
price+=2;
inventory.remove("price");
print(inventory);
}
}
}
function getmostexpensive()
{
for (price p:inventory)
if(p.getprice()>max)
{
price =p;
max=p.getprice();
}
}
function getleastexpensive()
{
for (price p:inventory)
if(p.getprice()>min)
{
price =p;
min=p.getprice();
}
}
function getbyitem()
{
for (item i:inventory)
if("i"is inventory)
{
print("item","price");
}
}
function getbyprice()
{
for (price p:inventory)
if("p"is inventory)
{
print("item","price");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.