Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build A Node.js module called inventory.js that exposes the following functionality: addItem - A function that takes 2 parameters: an items name and price and

Build A Node.js module called inventory.js that exposes the following functionality:

addItem - A function that takes 2 parameters: an items name and price and tracks it internally.

items - A function that returns a list of items, sorted by price from least expensive to most expensive.

getMostExpensive - Returns an object that contains the items name and price for the most expensive item that has been added.

getLeastExpensive - Returns an object that contains the items name and price for the most least expensive item that has been added.

removeItem - Remove an item by name.

getItemByName - Returns an items name and price by name.

getItemByPrice - Returns an items name and price by price.

Your module should not expose any functions or variables that would allow the above functions to have the integrity of their data compromised.

BELOW IS AN EXAMPLE OF HOW THE SCRIPT WILL BE USED.

'use strict';

const inventory = require('./inventory.js');

inventory.addItem('orange juice', 2.40);

inventory.addItem('milk', 4.00);

inventory.addItem('eggs', 1.20);

inventory.items().forEach(function (item) {

console.log(`Item ${item.name} costs ${item.price}`);

});

inventory.removeItem('milk');

let mostExpensive = inventory.getMostExpensive();

console.log(`${mostExpensive.name} at ${mostExpensive.price} costs the most!`);

let leastExpensive = inventory.getLeastExpensive();

console.log(`${leastExpensive.name} at ${leastExpensive.price} costs the least!`);

let itemByName = inventory.getItemByName('eggs');

console.log(`${itemByName.name} with price of ${itemByName.price} retrieved by name`);

let itemByPrice = inventory.getItemByPrice(2.40);

console.log(`${itemByPrice.name} with price of ${itemByPrice.price} retrieved by price`);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions