Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(array) {
- let pattern =
- /([\|#])(?<item>[a-zA-Z ]+)\1(?<date>\d{2}\/\d{2}\/\d{2})\1(?<calories>\d+)\1/g
- // /(?<separate>#|\|)(?<item>[A-Za-z ]+)\1(?<expDate>\d{2}\/\d{2}\/\d{2})\1(?<calories>\d+)/g;
- let result = []
- let sum = 0
- let match = pattern.exec(array[0])
- while (match !== null) {
- let date = match.groups.date
- let calories = match.groups.calories
- let items = match.groups.item
- sum += Number(calories)
- result.push([items, date, calories])
- match = pattern.exec(array[0])
- }
- let days = Math.floor(sum/2000)
- console.log(`You have food to last you for: ${days} days!`)
- result.forEach(el=>
- console.log(`Item: ${el[0]}, Best before: ${el[1]}, Nutrition: ${el[2]}`));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement