Advertisement
Guest User

Fancy Barcodes

a guest
Jul 31st, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let numberOfbarcode = Number(input.shift());
  4.  
  5.     let pattern = /(?<start>@#+)(?<barcode>[A-Za-z\dA-Z]{6,})(?<end>@#+)/g;
  6.     let code = '';
  7.  
  8.     for (const line of input) {
  9.         match = pattern.exec(line);
  10.  
  11.         if (match) {
  12.             for (const el of match.groups.barcode) {
  13.                 if (el.charCodeAt() >= 48 && el.charCodeAt() <= 57) {
  14.                     code += el;
  15.                 }
  16.             }
  17.             (code == '') ?
  18.             console.log(`Product group: 00`) :
  19.             console.log(`Product group: ${code}`)
  20.  
  21.         } else {
  22.             console.log(`Invalid barcode`);
  23.         }
  24.     }
  25. }
  26.  
  27.  
  28. solve([
  29.     '6',
  30.     '@###Val1d1teM@###',
  31.     '@#ValidIteM@#',
  32.     '##InvaliDiteM##',
  33.     '@InvalidIteM@',
  34.     '@#Invalid_IteM@#',
  35.     '@#ValiditeM@#'
  36.   ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement