File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed 
src/algorithms/string/knuth-morris-pratt Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ import knuthMorrisPratt from '../knuthMorrisPratt';
22
33describe ( 'knuthMorrisPratt' ,  ( )  =>  { 
44  it ( 'should find word position in given text' ,  ( )  =>  { 
5-     expect ( knuthMorrisPratt ( '' ,  '' ) ) . toBe ( - 1 ) ; 
6-     expect ( knuthMorrisPratt ( 'a' ,  '' ) ) . toBe ( - 1 ) ; 
5+     expect ( knuthMorrisPratt ( '' ,  '' ) ) . toBe ( 0 ) ; 
6+     expect ( knuthMorrisPratt ( 'a' ,  '' ) ) . toBe ( 0 ) ; 
77    expect ( knuthMorrisPratt ( 'a' ,  'a' ) ) . toBe ( 0 ) ; 
88    expect ( knuthMorrisPratt ( 'abcbcglx' ,  'abca' ) ) . toBe ( - 1 ) ; 
99    expect ( knuthMorrisPratt ( 'abcbcglx' ,  'bcgl' ) ) . toBe ( 3 ) ; 
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ function buildPatternTable(word) {
3030 * @return  {number } 
3131 */ 
3232export  default  function  knuthMorrisPratt ( text ,  word )  { 
33+   if  ( word . length  ===  0 )  { 
34+     return  0 ; 
35+   } 
36+ 
3337  let  textIndex  =  0 ; 
3438  let  wordIndex  =  0 ; 
3539
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments