function merge( A, m, B, n ) { // write code here let i = 0; let j = 0; let res = []; while(true) { res.push(A[i]<B[j] ? A[i++] : B[j++]); if (i === m -1) { while(j < n-1){ res.push(B[j++]); } } if (j === n-1) { while(i < m-1){ res.push(A[i++]); } } if (res.length === m +n) { return res; } } } // [4,5,6],3, [1,2,3],3