braveheart1989

3Count Occurrences

Oct 12th, 2016
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.     let match = input.shift ();
  3.     let result=[];
  4.     for (let name of input) {
  5.         let regex =  new RegExp(match,"g");
  6.         let exec = regex.exec(name);
  7.         while (exec) {
  8.             result.push(exec[0]);
  9.             exec = regex.exec(name);
  10.         }
  11.     }
  12.  
  13.     result != [] ? console.log(result.length) : console.log(0);
  14. }
RAW Paste Data