Building a Smart Inventory Management System

Story Welcome to TechStore, an innovative tech gadget retailer. As part of the development team, you have been tasked with creating a smart inventory management system to keep track of the store's products, their quantities, prices, and other relevant details. This system will help TechStore manage their inventory more efficiently, provide quick insights, and support decision-making.

Your goal is to use your knowledge of arrays and collections in JavaScript to build various functionalities of the inventory management system.

Objectives

By the end of this exercise, you will be able to:

  1. Create, manipulate, and transform arrays.
  2. Use higher-order functions such as map, filter, and reduce.
  3. Apply concepts of immutability and pure functions.
  4. Implement practical solutions for real-world problems using JavaScript arrays and collections.

Task 1: Initialize the Inventory

Create an array of product objects. Each product should have the following properties: id, name, category, quantity, and price.

Task 2: Add New Products

Implement a function addProduct that adds a new product to the inventory array. Ensure the function does not mutate the original array.

Task 3: Update Product Quantity

Create a function updateQuantity that updates the quantity of a specific product by its id. Ensure the function returns a new array and does not mutate the original.

Task 4: Remove a Product

Implement a function removeProduct that removes a product from the inventory based on its id. Ensure the function does not mutate the original array.

Task 5: Calculate Total Inventory Value

Create a function calculateTotalValue that calculates the total value of the inventory. The total value is the sum of the quantity of each product multiplied by its price.

Task 6: Filter Products by Category

Write a function filterByCategory that returns all products of a specific category.

Task 7: Sort Products by Price

Implement a function sortByPrice that sorts the products in the inventory by their price in ascending order.

Additional Challenge

Combine all the above tasks to create a comprehensive inventory management system. Implement a function manageInventory() that can perform all the operations based on a given action and parameters.