0% found this document useful (0 votes)
8 views4 pages

JS Requirement 1

jss

Uploaded by

Arun Prakash P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

JS Requirement 1

jss

Uploaded by

Arun Prakash P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Requirements to Write the JavaScript Function

1. Initialize Data:

• Create a list of books with duplicates. Each book object


should include:

❖ id: A unique identifier for the book.


❖ title: Name of the book.
❖ price: Price of the book in rupees.
❖ stock: The number of books available in stock.

• Create a list of customers of the bookstore. Each customer


object should include:

❖ id: A unique identifier for the customer.


❖ name: Name of the customer.
❖ isExistingCustomer: Boolean indicating if they are a
returning customer.
❖ lastPurchase: Details of the last purchase (optional).

2. Functionality:

• Remove Duplicates:
Use a Set to remove duplicate entries from the book list based on the
book’s id.

• Get Customer’s Chosen Books:


Take a list of book ids as input and filter the books from the inventory
based on the selection.
• Calculate Discount:

• For existing customers:

➢ Provide a 15% discount on books priced above ₹200.

• For new customers:

➢ Discount based on the price range:


➔ ₹100–₹200: 2%
➔ ₹200–₹500: 5%
➔ ₹500–₹750: 10%
➔ Above ₹750: 15%.

• Prepare Bill:

• Calculate the total price after applying the discount.

• Include a breakdown of the purchase:

❖ Book titles.
❖ Quantity.
❖ Individual prices before and after discount.
❖ Total price.
❖ Discount applied.

• Format the bill as an object.

• Update Stock:
Reduce the stock count for each book purchased.

• Update Customer Details:


Update the customer’s lastPurchase with details of the recent purchase,
including the date, books purchased, and total amount.

3. Technical Requirements:
• Use map and filter for processing arrays.

• Use Set to eliminate duplicates.

• Apply if...else or switch for conditional discount logic.

• Use objects and arrays for organizing data.

• Utilize appropriate operators (+=, -=, etc.) to handle stock


updates and calculations.

4. Output:
The function should return:

• A formatted bill object.

• Updated stock and customer details.

5. Sample Execution:

Input:

const bookIds = [1, 2, 2, 3]; // Books chosen by the customer


const customerId = 101; // Customer making the purchase

Output:
{
bill: {
customerName: 'John Doe',
booksPurchased: [
{ title: 'Book A', quantity: 1, price: 300, discount: 45, finalPrice: 255 },
{ title: 'Book B', quantity: 1, price: 150, discount: 3, finalPrice: 147 }
],
totalPrice: 402,
totalDiscount: 48,
},
}

updatedStock: [...],

updatedCustomerDetails: { ... },

You might also like