File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
packages/react-error-overlay/src/utils Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,15 @@ import { getLinesAround } from './getLinesAround';
5
5
import path from 'path' ;
6
6
7
7
function count ( search : string , string : string ) : number {
8
- let count = - 1 , index = 0 ;
9
- for ( ; index !== - 1 ; count ++ , ( index = string . indexOf ( search , index + 1 ) ) ) ;
8
+ // Count starts at -1 becuse a do-while loop always runs at least once
9
+ let count = - 1 , index = - 1 ;
10
+ do {
11
+ // First call or the while case evaluated true, meaning we have to make
12
+ // count 0 or we found a character
13
+ ++ count ;
14
+ // Find the index of our search string, starting after the previous index
15
+ index = string . indexOf ( search , index + 1 ) ;
16
+ } while ( index !== - 1 ) ;
10
17
return count ;
11
18
}
12
19
You can’t perform that action at this time.
0 commit comments