Advertisement
Guest User

Untitled

a guest
Aug 7th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fancy(input = []) {
  2.     let num = Number(input.shift());
  3.     //let barcodePattern = /(@#|@#)([A-Z][a-z]+)[A-Z][a-z]+[A-Z]\1/g;
  4.     let pattern = /^@#+(?=[A-Z])([A-Za-z0-9]{6,})(?<=[A-Z])@#+$/m
  5.  
  6.  
  7.     let string = "";
  8.     for (let i = 1; i <= num; i++) {
  9.         let data = input.shift();
  10.         let match = pattern.exec(data);
  11.  
  12.         if (match !== null) {
  13.             let matches = match[1];
  14.  
  15.             for (let i = 0; i < matches.length; i++) {
  16.                 if (matches.charCodeAt(i) >= 48 && matches.charCodeAt(i) <= 57) {
  17.                     string += matches[i];
  18.                 }
  19.  
  20.             }
  21.             if (!matches.match('[0-9]+')) {
  22.                 console.log(`Product group: 00`);
  23.             }
  24.             if (matches.match('[0-9]+')) {
  25.                 console.log(`Product group: ${string}`);
  26.                 string = "";
  27.             }
  28.         } else {
  29.             console.log(`Invalid barcode`);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement