本文主要和大家分享js实现多个字符串首尾重复进行拼接,字符串数组,字符串之间首尾重复,去除重复部分,进行拼接,希望能帮助到大家。
var j=0;
var isrepeat = null
var index = null
var res = new array()
var tmp_key2
var tmp_key1
var repeat = function(ary) {
var arr1 = tmp = ary;
for(var i=0; i<ary.length; i++){
tmp_key1 = ary[i];
var len1 = tmp_key1.length;
ccc:
for(j = 0 ; j<arr1.length; j++){
if(i===j){
continue;
}
tmp_key2 = arr1[j];
var len2 = tmp_key2.length;
index = -1;
var index_num =0;
for(var k = 0; k < len2; k++) {
var tmp_str = tmp_key2.slice(0,k+1);
index = tmp_key1.indexof(tmp_str);
if(index !== -1){
isrepeat = index;
}
if( isrepeat != null && index ===-1 ){
break ccc;
}
}
}
// console.log(isrepeat);
if(isrepeat !== null) {
res.push(tmp_key1.slice(0,isrepeat)+tmp_key2)
}
index = null;
isrepeat = null;
}
console.log(res);
return res;
}
var ary = new array("中国红","红红火火","zhanglei","lei@silenc","kkkzhang");
repeat(ary);
["中国红红火火", "zhanglei@silenc", "kkkzhanglei"]
以上就是js实现多个字符串首尾重复拼接的详细内容。