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';
55import path from 'path' ;
66
77function 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 ) ;
1017 return count ;
1118}
1219
You can’t perform that action at this time.
0 commit comments