Analyze a product inventory dataset in script.js by selecting in-stock items, sorting expensive ones, and totaling inventory value. The previous lesson used recursion for nested inputs; this flat list is a better fit for array methods.
const books = [
{ title: "Orbit", available: true },
{ title: "Harbor", available: false }
];
const labels = books.filter((book) => book.available).map((book) => book.title);
console.log(labels);
inStockItems by filtering for positive stock.expensiveItems as names priced at least $300, in descending price order.totalValue(items) to sum each price multiplied by stock.byCategory(items) to group all records into category-keyed arrays.inStockItems.expensiveItems.totalValue(inventory).Chain: data.filter(...).map(...).reduce(...) for clean pipelines.
Use sort() with a comparator to sort by a numeric field.
Group using reduce: accumulate into an object keyed by category.