Closed lyflove closed 3 years ago
let arrA = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2']; let arrB = ['A', 'B', 'C', 'D']; function concatAndSort(arrA,arrB){ let arrC = [].concat(arrA); let j = 0; let count = 0; for(let i=0;i<arrB.length;i++){ console.log(j); while(j<arrA.length){ let astr = arrA[j],bstr = arrB[i]; if(astr.startsWith(bstr)){ j++; }else{ if(j===arrA.length-1){ arrC.push(bstr); break; }else{ arrC.splice(j+count,0,bstr); count++; break; } } }
} return arrC; }
let arrC = concatAndSort(arrA,arrB); console.log(arrC);
let arrA = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2']; let arrB = ['A', 'B', 'C', 'D']; function concatAndSort(arrA,arrB){ let arrC = [].concat(arrA); let j = 0; let count = 0; for(let i=0;i<arrB.length;i++){ console.log(j); while(j<arrA.length){ let astr = arrA[j],bstr = arrB[i]; if(astr.startsWith(bstr)){ j++; }else{ if(j===arrA.length-1){ arrC.push(bstr); break; }else{ arrC.splice(j+count,0,bstr); count++; break; } } }
let arrC = concatAndSort(arrA,arrB); console.log(arrC);