In this program merged two array and then sorted using temp.but this not correct method.because two array are sorted ,so method should be unique i.e. merging of two sorted i
Fastest Merge of 2 Sorting array
function merge(a, b) {
let i = 0,
j = 0;
let array = [];
let counter = 0;
while (i < a.length && j < b.length) {
if (a[i] > b[j]) array[counter++] = b[j++];
else if (a[i] < b[j]) array[counter++] = a[i++];
else (array[counter++] = a[i++]), j++;
}
while (j < b.length) {
array[counter++] = b[j++];
}
while (i < a.length) {
array[counter++] = a[i++];
}
return array;
}
console.log(merge([1, 3], [2, 4, 5]));
console.log(merge([1, 3, 123, 125, 127], [2, 41, 50]));