Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function astra(input){
- //let pattern=/(#|\|)(?<item>[A-Za-z]+)\1(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<cal>\d+)\1/g;
- let string=input.shift();
- let matches=Array.from(string.matchAll(/(#|\|)(?<item>[A-Z\sa-z]+)\1(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<calories>\d+)\1/g));
- let totalCal=0;
- let daily=0;
- for(let match of matches){
- let calories=Number(match.groups.calories);
- totalCal+=calories;
- daily=Math.floor(totalCal/2000);
- }
- console.log(`You have food to last you for: ${daily} days!`)
- for(let match of matches){
- let product=match.groups.item;
- let exp=match.groups.date;
- let cals=Number(match.groups.calories)
- console.log(`Item: ${product}, Best before: ${exp}, Nutrition: ${cals}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement