Skip to content

Instantly share code, notes, and snippets.

@Sarav-S
Created July 10, 2020 02:39
Show Gist options
  • Save Sarav-S/c7aa8b72f090dd1354327883492821b2 to your computer and use it in GitHub Desktop.
Save Sarav-S/c7aa8b72f090dd1354327883492821b2 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 = [];
for (let i = 0; i < items.length; i++) {
if (items[i].in_stock)
inStockItems.push(items[i]);
}
let total = 0;
for (let i = 0; i < inStockItems.length; i++) {
total += inStockItems[i].price;
}
console.log(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment