Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function adAstra(data) {
- let regex = /([\#\|])(?<product>[A-Z a-z]+)\1(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})\1(?<calories>[\d]+)\1/g
- let totalCalories = 0
- while (regex.test(data)) {
- let currLine = regex.exec(data);
- let product = currLine.groups.product;
- let date = currLine.groups.date;
- let calories = Number(currLine.groups.calories);
- console.log(product)
- console.log(date)
- console.log(calories)
- }
- }
- adAstra(['#Bread#19/03/21#4000#|Invalid|03/03.20||Apples|08/10/20|200||Carrots|06/08/20|500||Not right|6.8.20|5|'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement