1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| let str = `반응형웹, 반응형 웹, Responsive, responsive web 웹표준 웹표준, 웹 표준, Web Standard, web Standard`;
const homonym = ['웹 표준', '웹표준', 'Web Standard'];
const countHomonym = (homonym, str) => { let cnt = 0; for(const word of homonym) { const regExp = new RegExp(word, 'gmi'); const matchedWords = str.match(regExp); if(matchedWords) cnt += matchedWords.length; } return cnt; };
console.log(countHomonym(homonym, str));
|