Advertisement
bebo231312312321

Untitled

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