Open 1684838553 opened 2 years ago
/**
* @param {string} big
* @param {string[]} smalls
* @return {number[][]}
*/
var multiSearch = function(big, smalls) {
let result = []
smalls.forEach(item => {
const position = getPosition(big, item)
result.push(position)
})
return result
};
const getPosition = (big, str) => {
const ans = []
if(!str || str.length > big.length) return ans
let index = big.indexOf(str)
while(index > -1){
ans.push(index)
index = big.indexOf(str, index + str.length)
}
return ans
}
indexOf(searchElement, fromIndex)
// fromIndex 开始查找的位置。sentence.replace(new RegExp(word,'g'), ' ')
replace中使用变量