Last active
July 10, 2020 02:43
-
-
Save Sarav-S/8dae3d460cb0c11e5094691de2845e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | |
]; | |
function inStockItems(items) { | |
const inStockItems = []; | |
for (let i = 0; i < items.length; i++) { | |
if (items[i].in_stock) | |
inStockItems.push(items[i]); | |
} | |
return inStockItems; | |
} | |
function total(items) { | |
let total = 0; | |
for (let i = 0; i < items.length; i++) { | |
total += items[i].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