Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const products = [
- {
- id: 1,
- name: 'butter',
- price: '5pln'
- },
- {
- id: 2,
- name: 'bread',
- price: '4 pln'
- },
- {
- id: 3,
- name: 'eggs',
- price: '3'
- }
- ];
- const getTotalPrice = (totalPriceSoFar, { price: nextProductPrice }) =>
- totalPriceSoFar + +nextProductPrice.replace(/(\d+)(.*)/, '$1');
- const totalPrice = products.reduce(getTotalPrice, 0);
- console.log(`Total price of products: ${totalPrice}`);
Add Comment
Please, Sign In to add comment