Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function furniture(arr) {
- let regex = />>(?<furniture>[A-Z]+[a-z]*)<<(?<price>\d+\.*\d*)!(?<quantity>\d+)\b/g;
- let furniture = [];
- let totalPrice = 0;
- while ((data = regex.exec(arr)) !== null) {
- let items = data.groups['furniture'];
- furniture.push(items);
- let price = data.groups['price'];
- let quantity = data.groups['quantity'];
- let itemPrice = price * quantity;
- totalPrice += itemPrice;
- }
- if (furniture.length === 0) {
- console.log(`Bought furniture:`);
- console.log(`Total money spend: ${totalPrice.toFixed(2)}`);
- return;
- }
- console.log(`Bought furniture:\n${furniture.join('\n')}`);
- console.log(`Total money spend: ${totalPrice.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement