Skip to content

Instantly share code, notes, and snippets.

@Sarav-S
Created July 10, 2020 02:51
Show Gist options
  • Save Sarav-S/5bf234603e35930db90f9dd2ed89e6e8 to your computer and use it in GitHub Desktop.
Save Sarav-S/5bf234603e35930db90f9dd2ed89e6e8 to your computer and use it in GitHub Desktop.
const items = [
{name: "Item 1", price: 20, in_stock: true},
{name: "Item 2", price: 40, in_stock: true},
{name: "Item 3", price: 40, in_stock: false},
];
const inStockItems = items => items.filter(item => item.in_stock);
const total = items => {
let total = 0;
items.forEach(item => total += item.price);
return total;
}
console.log(total(inStockItems(items)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment