📅  最后修改于: 2022-03-11 15:03:34.648000             🧑  作者: Mango
// using for single for loop
let arrrone = [0,3,4,31];
let arrayTwo = [4,6,30,31,33];
let j = 0;
let k = 0;
let mergedArray = [];
let length = arrrone.length + arrayTwo.length;
console.log(length)
for(let i = 0; i<= length - 1; i++){
if(arrrone[j] < arrayTwo[k]){
mergedArray.push(arrrone[j]);
j++;
}
else if(arrrone[j] > arrayTwo[k]){
mergedArray.push(arrayTwo[k]);
k++;
}
else if(arrrone[j] == arrayTwo[k]){
mergedArray.push(arrrone[j]);
mergedArray.push(arrayTwo[k]);
j++;
k++;
}
}
console.log(mergedArray)