ARTICLEViews: 9Share  Posted by - Anonymous

function countCounterfeit - serialNumber

function countCounterfeit(serialNumber) {


  // Write your code here


  let unique = (str) => {


    let strArr = str.split("");


    return strArr[0] !== strArr[1] && strArr[1] !== strArr[2];


  };


  var patt = new RegExp("([A-Z]+)([0-9]{4})([0-9]+)([A-Z]+)");


   var bill = 0;


   var validNotes = ["10","20","50","100","200","500","1000"];


   


    serialNumber.forEach(el => {


      var res = patt.exec(el); 


      if(res 


        && el.length >= 10 && el.length <= 12


        && res[1].length === 3 && unique(res[1]) 


        && res[4].length === 1 


        && validNotes.indexOf(res[3]) > -1


        && (parseInt(res[2]) >= 1900 && parseInt(res[2]) <= 2019)


       ){


        bill = bill + parseInt(res[3]);


      }


    });


  return bill;


}


Auto Suggestions & Related Videos -

Views -