text
를 공백을 기준으로 분리first
와 second
가 연달아 나온 후의 단어인지 확인result
에 pushfunction findOcurrences(text: string, first: string, second: string): string[] {
const words = text.split(' ')
const result = []
for(let i = 2; i < words.length; i++) {
const firstPrev = words[i - 2]
const secondPrev = words[i - 1]
if(firstPrev === first && secondPrev === second) result.push(words[i])
}
return result
};