Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function softUniBarIncome(input) {
- let totalPrice = 0
- const path = /%(?<name>[A-Z][a-z]*)%.*?<(?<product>\w+)>.*?\|(?<quant>\d+)\|.*?(?<price>[\d]+[.]?\d+)\$/
- input.slice(0, input.length - 1).forEach((element, index) => {
- if ((path.exec(element)) !== null) {
- let maches = path.exec(element)
- let sum = maches.groups.quant * maches.groups.price
- totalPrice += sum
- console.log(`${maches[1]}: ${maches[2]} - ${sum.toFixed(2)}`)
- }
- });
- console.log(`Total income: ${totalPrice.toFixed(2)}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement