Cómo fusionar dos matrices ordenadas en JavaScript
// 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)
talhadev