Advertisement
bebo231312312321

Untitled

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