const naiveSearchPatter = (searchPattern, string) => {
const M = searchPattern.length;
const N = string.length;
const indexArray = [];
for (let i = 0; i <= N-M; i++) {
let j;
for (j = 0; j < M; j++) {
if (string[i+j] != searchPattern[j])
break;
}
if (j == M) {
indexArray.push(i)
}
}
return indexArray;
};
console.log(naiveSearchPatter("bc", "abcd"));
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)