Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function furniture(array) {
- let tempTotal = 0;
- let pattern = /\b(?<name>[A-Z]+[a-z]*)\<{2}(?<price>\d+\.*\d*)\!(?<quantity>\d{1,})/g
- console.log('Bought furniture:')
- for (const str of array) {
- let match = pattern.exec(str)
- while (match !== null) {
- let name = match.groups['name'];
- let price = Number(match.groups['price']);
- let quantity = Number(match.groups['quantity']);
- match = pattern.exec(str);
- console.log(`${name}`);
- tempTotal += (price * quantity);
- }
- }
- console.log(`Total money spend: ${tempTotal.toFixed(2)}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment