Skip to content

Commit e817fbc

Browse files
committed
Add case when the searching string is the string we're looking for
1 parent aa749bf commit e817fbc

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎src/searching/knuth-morris-pratt.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
* time, or -1 if it never occurs.
4747
*/
4848
function indexOf(str, substr) {
49+
if (str === substr) {
50+
return 0;
51+
}
4952
var table = builtKMPTable(substr);
5053
var i = 0;
5154
var j = 0;

0 commit comments

Comments
 (0)