From 4fb8969f6994d8414f388f583d8e270d4e4a67e9 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 23 Mar 2018 11:11:09 -0400 Subject: ya --- frontend/lib/calcTotalPrice.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 frontend/lib/calcTotalPrice.js (limited to 'frontend/lib') diff --git a/frontend/lib/calcTotalPrice.js b/frontend/lib/calcTotalPrice.js new file mode 100644 index 0000000..4822468 --- /dev/null +++ b/frontend/lib/calcTotalPrice.js @@ -0,0 +1,6 @@ +export default function calcTotalPrice(cart) { + return cart.reduce((tally, cartItem) => { + if (!cartItem.item) return tally; + return tally + cartItem.quantity * cartItem.item.price; + }, 0); +} -- cgit v1.3