Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fancyBarcodes(array) {
- let codesNumber = array.shift();
- let regex = /@#+(?<barcode>[A-Z][a-zA-Z0-9]{4,}[A-Z])@#/;
- for (let i = 0; i < codesNumber; i++) {
- let string = regex.exec(array[i]);
- if (string !== null) {
- let valid = string.groups.barcode;
- let productGroup = ``;
- for (let currSymbol of valid) {
- if (isNaN(currSymbol) === false) {
- productGroup += currSymbol;
- }
- }
- if (productGroup == ``) {
- productGroup = `00`;
- }
- console.log(`Product group: ${productGroup}`);
- } else {
- console.log("Invalid barcode");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement