Skip to content

Commit b4458b7

Browse files
committed
Add naive search
1 parent b8930ad commit b4458b7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const naiveSearch = (longStr, shortStr) => {
2+
let count = 0;
3+
4+
for (let i = 0; i < longStr.length; i++) {
5+
for (let j = 0; j < shortStr.length; j++) {
6+
if (shortStr[j] !== longStr[i + j]) {
7+
console.log('Break!!!');
8+
break;
9+
}
10+
if (j === shortStr.length - 1) {
11+
console.log('Found one');
12+
count++;
13+
}
14+
}
15+
}
16+
return count;
17+
};
18+
19+
console.log(naiveSearch('manmamaasasas', 'ma'));

0 commit comments

Comments
 (0)