function kmpGetStrPartMatchValue(str) {
var prefix = [];
var c =0,j=str.length;i
var newStr = str.substring(0,i 1);
partMatch[ i] = 0;
} else {
for(var k=0;k suffix [k] = newStr.slice(-k-1);
if(prefix[k]== suffix ] = prefix[k].length;
}
}
if(!partMatch[i]){ }
}
prefix.length = 0
;
prefix.length = 0
;
;
; suffix.length = 0;
return partMatch;
}
//demo
var t="ABCDABD";console.log(kmpGetStrPartMatchValue(t));//output:[0,0,0,0,1,2,0 ]
回退演算法實作如下: