Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let numberOfbarcode = Number(input.shift());
- let pattern = /(?<start>@#+)(?<barcode>[A-Z][a-z\dA-Z]{4,}[A-Z])(?<end>@#+)/;
- let code = '';
- for (const line of input) {
- match = pattern.exec(line);
- code = ''
- if (match) {
- for (const el of match.groups.barcode) {
- if (el.charCodeAt() >= 48 && el.charCodeAt() <= 57) {
- code += el;
- }
- }
- (code == '') ?
- console.log(`Product group: 00`) :
- console.log(`Product group: ${code}`)
- } else {
- console.log(`Invalid barcode`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement