Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(input) {
- let pattern = /([|#])(?<itemName>[A-Za-z ]+)\1(?<exp>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<cal>\d+)\1/gm;
- let text = input[0];
- let totalCalories = 0;
- let result = [];
- let matches = pattern.exec(text);
- while(matches !== null) {
- let info = [];
- let itemName = matches.groups.itemName;
- let expDate = matches.groups.exp;
- let calories = matches.groups.cal;
- info.push(itemName,expDate,calories);
- result.push(info);
- totalCalories += Number(calories);
- matches = pattern.exec(text);
- }
- let days = Math.floor(totalCalories/2000);
- console.log(`You have food to last you for: ${days} days!`);
- for(const array of result) {
- console.log(`Item: ${array[0]}, Best before: ${array[1]}, Nutrition: ${array[2]}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment