Advertisement
bebo231312312321

Untitled

Mar 24th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fancybarCode(input) {
  2.     let numGroups = input.shift();
  3.     let firstPattern = /(@#{1,})([A-Z][A-Za-z\d]{4,}[A-Z])(@#{1,})/g
  4.     let secondPatern = /\d+/g
  5.  
  6.  
  7.     // /(@[#]+)(?<name>[A-Za-z0-9]){6,}\1/g
  8.  
  9.  
  10.     for (let el of input) {
  11.  
  12.         let matches = (el.match(firstPattern) )
  13.         if (matches!==null) {
  14.            
  15.                 let word = matches[0];
  16.  
  17.                 let digitChars = [...word].filter(digit => /\d/.test(digit)).join("");
  18.                 let result = digitChars === "" ? '00' : digitChars;
  19.                 console.log(`Product group: ${result}`);
  20.  
  21.            
  22.         } else {
  23.             console.log("Invalid barcode")
  24.         }
  25.     }
  26.  
  27.  
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement