Find A Sub-Word

  • + 0 comments

    Javascript:

    const lines = input.split(/^\d+\s(?=.*$)/gm);
    const words = lines[2].split("\n");
    words.forEach((word) => {
      const regex = new RegExp(`(?<!\\b)${word}(?!\\b)`, 'g');
      const sum = lines[1].match(regex)?.length || 0;
      console.log(sum);
    });