Guest User

Untitled

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. const products = [
  2. {
  3. id: 1,
  4. name: 'butter',
  5. price: '5pln'
  6. },
  7. {
  8. id: 2,
  9. name: 'bread',
  10. price: '4 pln'
  11. },
  12. {
  13. id: 3,
  14. name: 'eggs',
  15. price: '3'
  16. }
  17. ];
  18.  
  19. const getTotalPrice = (totalPriceSoFar, { price: nextProductPrice }) =>
  20. totalPriceSoFar + +nextProductPrice.replace(/(\d+)(.*)/, '$1');
  21.  
  22. const totalPrice = products.reduce(getTotalPrice, 0);
  23.  
  24. console.log(`Total price of products: ${totalPrice}`);
Add Comment
Please, Sign In to add comment