Advertisement
bebo231312312321

Untitled

Mar 20th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function adAstra(array) {
  2.     let pattern =
  3.     /([\|#])(?<item>[a-zA-Z ]+)\1(?<date>\d{2}\/\d{2}\/\d{2})\1(?<calories>\d+)\1/g
  4.     // /(?<separate>#|\|)(?<item>[A-Za-z ]+)\1(?<expDate>\d{2}\/\d{2}\/\d{2})\1(?<calories>\d+)/g;
  5.     let result = []
  6.     let sum = 0
  7.     let match = pattern.exec(array[0])
  8.  
  9.     while (match !== null) {
  10.         let date = match.groups.date
  11.         let calories = match.groups.calories
  12.         let items = match.groups.item
  13.         sum += Number(calories)
  14.         result.push([items, date, calories])
  15.  
  16.         match = pattern.exec(array[0])
  17.     }
  18.     let days = Math.floor(sum/2000)
  19.     console.log(`You have food to last you for: ${days} days!`)
  20.   result.forEach(el=>
  21.  
  22.        console.log(`Item: ${el[0]}, Best before: ${el[1]}, Nutrition: ${el[2]}`));
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement