Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkBarcodes(input) {
- let barcodeCount = Number(input.shift());
- let barcodesToCheck = input.slice(0, barcodeCount);
- let validBarcodePattern = /@#+[A-Z][A-Za-z\d]{4,}[A-Z]@#+/;
- let digitsPattern = /\d/g;
- barcodesToCheck.forEach(barcode => {
- if (!barcode.match(validBarcodePattern)) {
- console.log('Invalid barcode');
- } else {
- let currentBarcode = barcode.match(digitsPattern)
- if (currentBarcode === null) {
- console.log('Product group: 00');
- } else {
- console.log(`Product group: ${currentBarcode.join('')}`);
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement