Skip to content

Instantly share code, notes, and snippets.

@halan
Last active February 18, 2017 21:26
Show Gist options
  • Save halan/6d5031251df7045aa339f9686cdc1df3 to your computer and use it in GitHub Desktop.
Save halan/6d5031251df7045aa339f9686cdc1df3 to your computer and use it in GitHub Desktop.
const lineItems = [
{ name: 'Carmenere', price: 35, quantity: 2 },
{ name: 'Cabernet', price: 50, quantity: 1 },
{ name: 'Merlot', price: 98, quantity: 10 },
];
const sumTotal = lines => {
let total = 0;
for(let i = 0; i < lines.length; i++) {
total += lines[i].quantity * lines[i].price;
}
return total;
}
console.log(sumTotal(lineItems)); // 1100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment