输入:text = "alice is a good girl she is a good student", first = "a", second = "good"
输出:["girl","student"]
输入:text = "we will we will rock you", first = "we", second = "will"
输出:["we","rock"]
/**
* @param {string} text
* @param {string} first
* @param {string} second
* @return {string[]}
*/
var findOcurrences = function (text, first, second) {
let arr = text.split(' ');
let res = []
arr.forEach((word, index) => {
if (index < arr.length - 2) {
if (word === first && arr[index + 1] === second) {
res.push(arr[index + 2])
}
}
});
return res;
};
findOcurrences('we will we will rock you', 'we', 'will')