Skip to content

Instantly share code, notes, and snippets.

@halan
Last active February 23, 2017 15:16
Show Gist options
  • Save halan/89d973205fae2fe4b72c6405d9c9f413 to your computer and use it in GitHub Desktop.
Save halan/89d973205fae2fe4b72c6405d9c9f413 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 totalLine = line =>
line.quantity * line.price;
const sumTotal = lines =>
lines.reduce((total, line) => total += totalLine(line), 0);
console.log(sumTotal(lineItems));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment