Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(text) {
- let regex = /([|#])(?<food>[a-z\sA-Z]+)\1(?<expDate>(\d{2})\/\d{2}\/\d{2})\1(?<calories>\d+)\1/g;
- let days = 0;
- let totalCalories = 0;
- let buff = '';
- while ((matches = regex.exec(text)) !== null) {
- let foodName = matches.groups['food'];
- let expiryDate = matches.groups['expDate'];
- let calories = Number(matches.groups['calories']);
- totalCalories += calories;
- buff += `Item: ${foodName}, Best before: ${expiryDate}, Nutrition: ${calories}\n`;
- }
- days = Math.floor(totalCalories / 2000);
- console.log(`You have food to last you for: ${days} days!`);
- console.log(buff);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement