Advertisement
divanov94

Untitled

Sep 21st, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function astra(input){
  2.     //let pattern=/(#|\|)(?<item>[A-Za-z]+)\1(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<cal>\d+)\1/g;
  3.     let string=input.shift();
  4.     let matches=Array.from(string.matchAll(/(#|\|)(?<item>[A-Z\sa-z]+)\1(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<calories>\d+)\1/g));
  5.     let totalCal=0;
  6.     let daily=0;
  7.  
  8.     for(let match of matches){
  9.  
  10.         let calories=Number(match.groups.calories);
  11.         totalCal+=calories;
  12.         daily=Math.floor(totalCal/2000);
  13.  
  14.  
  15.  
  16.  
  17.  
  18.     }
  19.     console.log(`You have food to last you for: ${daily} days!`)
  20.     for(let match of matches){
  21.         let product=match.groups.item;
  22.         let exp=match.groups.date;
  23.         let cals=Number(match.groups.calories)
  24.         console.log(`Item: ${product}, Best before: ${exp}, Nutrition: ${cals}`)
  25.     }
  26.  
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement