{
let largerString = `const cart = [];
function addItem(item) {
cart.push(item);
}
function removeItem(itemName) {
const index = cart.findIndex(item => item.name === itemName);
if (index !== -1) {
cart.splice(index, 1);
}
}
function calculateTotalPrice() {
let totalPrice = 0;
for (let item of cart) {
totalPrice += item.price * item.quantity; // Updated to multiply by the quantity
}
return totalPrice;
}
function viewCart() {
for (let item of cart) {
console.log(\`Item: \${item.name}, Price: \${item.price}, Quantity: \${item.quantity}\`); // Updated to display the quantity
}
}
// Test the functionality
const item1 = { name: 'Apple', price: 0.5, quantity: 2 }; // Added quantity property
const item2 = { name: 'Banana', price: 0.25, quantity: 3 }; // Added quantity property
addItem(item1);
addItem(item2);
viewCart(); // Output: Item: Apple, Price: 0.5, Quantity: 2
// Item: Banana, Price: 0.25, Quantity: 3
removeItem('Apple');
viewCart(); // Output: Item: Banana, Price: 0.25, Quantity: 3
console.log(\`Total Price: \${calculateTotalPrice()}\`); // Output: Total Price: 0.75`
let substring = `function calculateTotalPrice() {
let totalPrice = 0;
for (let item of cart) {
totalPrice += item.price * item.quantity;
}
return totalPrice;
}`;
const {start, end} = fuzzyFindSubstringIndices(largerString, substring)
return largerString.slice(start, end)
}