UK and US: Part 2

  • + 0 comments

    Javascript:

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