该脚本在字符串数组中搜索最大的子字符串。但是如果字符串不是以"A“开头,搜索就会失败。如何实现内置子字符串的搜索?("ABCDE","XBCDJL") = BCD
var array = ["ABCDEFZ", "ABCDXYZ"],
prefix = array[0],
len = prefix.length;
for (i=1; i<array.length; i++) {
for (j=0, len=Math.min(len,array[j].length); j<len; j++) {
if (prefix[j] != array[i][j]) {
len = j;
prefix = prefix.substr(0, len);
break;
}
}
}
https://stackoverflow.com/questions/52934992
复制相似问题