Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const input = args.slice(1);
- const pattern = /^(?<start>@#+)(?<barcode>[A-Z][A-Za-z0-9]{4,}[A-Z])(?<end>@#+)$/;
- input.forEach((line) => {
- let code = '';
- const match = pattern.exec(line);
- 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');
- }
- });
- }
Add Comment
Please, Sign In to add comment