Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(input) {
- let calsPerDay = 2000;
- let totalCals = 0;
- let arr = [];
- let info = input.shift();
- let regex =
- /([#\|])(?<item>[A-Za-z\s]+)\1(?<date>[0-9]{2}\/[0-9]{2}\/[0-9]{2})\1(?<cals>\d{0,10000})\1/g;
- let match = regex.exec(info);
- while (match) {
- arr.push(match[0]);
- match = regex.exec(info);
- }
- for (let infoFood of arr) {
- let [, itemName, expirationDate, calories] = infoFood.split(/[#|]/g);
- calories = Number(calories);
- totalCals += calories;
- }
- let days = Math.floor(totalCals / calsPerDay);
- console.log(`You have food to last you for: ${days} days!`);
- if (days > 0) {
- for (let infoFood of arr) {
- let [, itemName, expirationDate, calories] = infoFood.split(/[#|]/g);
- console.log(
- `Item: ${itemName}, Best before: ${expirationDate}, Nutrition: ${calories}`
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment