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-Za-z\dA-Z]{6,})(?<end>@#+)/g;
- let code = '';
- for (const line of input) {
- 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`);
- }
- }
- }
- solve([
- '6',
- '@###Val1d1teM@###',
- '@#ValidIteM@#',
- '##InvaliDiteM##',
- '@InvalidIteM@',
- '@#Invalid_IteM@#',
- '@#ValiditeM@#'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement