Advertisement
dabidabidesh

barcode 30->100

Jul 31st, 2020
2,567
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-Z][a-z\dA-Z]{4,}[A-Z])(?<end>@#+)/;
  6.   let code = '';
  7.  
  8.   for (const line of input) {
  9.     match = pattern.exec(line);
  10.     code = ''
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement