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
Shortest Merge Sorted arrays without sort() plus, without using third temp array.
function mergeSortedArray (a, b){ let index = 0; while(b.length > 0 && a[index]) { if(a[index] > b[0]) { a.splice(index, 0, b.shift()); } index++; } return [...a, ...b]; } mergeSortedArray([1,2,3,5,9],[4,6,7,8])