Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(input) {
- let maches = input[0].match(/([|#])([A-Za-z\s]+)\1(\d{2}\/\d{2}\/\d{2})\1(\d{1,5})\1/g);
- let products = [];
- let sumCalories = 0;
- if (maches) {
- for (let match of maches) {
- let m = match.split(match.includes("#") ? "#" : "|").filter(x => x !== "");
- products.push({ name: m[0], date: m[1], calories: m[2] });
- sumCalories += Number(m[2]);
- }
- }
- console.log(`You have food to last you for: ${Math.floor(sumCalories / 2000)} days!`);
- for (let p of products) {
- console.log(`Item: ${p.name}, Best before: ${p.date}, Nutrition: ${p.calories}`);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement