Advertisement
Pijomir

Fancy Barcodes

Nov 27th, 2023
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkBarcodes(input) {
  2.     let barcodeCount = Number(input.shift());
  3.     let barcodesToCheck = input.slice(0, barcodeCount);
  4.     let validBarcodePattern = /@#+[A-Z][A-Za-z\d]{4,}[A-Z]@#+/;
  5.     let digitsPattern = /\d/g;
  6.     barcodesToCheck.forEach(barcode => {
  7.         if (!barcode.match(validBarcodePattern)) {
  8.             console.log('Invalid barcode');
  9.         } else {
  10.             let currentBarcode = barcode.match(digitsPattern)
  11.             if (currentBarcode === null) {
  12.                 console.log('Product group: 00');
  13.             } else {
  14.                 console.log(`Product group: ${currentBarcode.join('')}`);
  15.             }
  16.         }
  17.     });
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement