Assignment
import { teas } from "../data/teas.js";Exercise 1: Rewrite with Array Methods
const result = [];
for (let i = 0; i < teas.length; i++) {
if (teas[i].caffeineLevel !== "none") {
result.push(teas[i].name.toUpperCase());
}
}
console.log(result);Exercise 2: Inventory Report ⭐
function inventoryReport(teas) {
return {
totalTeas: /* total number of teas */,
inStock: /* number of teas where inStock is true */,
outOfStock: /* number of teas where inStock is false */,
totalInventoryValue: /* sum of (pricePerGram * stockCount) for all teas */,
averagePrice: /* average pricePerGram across all teas */
};
}
console.log(inventoryReport(teas));Exercise 3: Low Stock Alert
Exercise 4: Teas by Origin ⭐⭐
Exercise 5: Search Function
Optional: reduce
Exercise 6: Total Inventory Value (Optional)
Exercise 7: Count by Type (Optional)
Submission
Last updated