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
If you don't care about performance of the sort operation, you can use Array.sort:
var a=[1,2,3,5,9]; var b=[4,6,7,8]; var c = a.concat(b).sort((a,b)=>a > b); console.log(c)
Of course, using the knowledge that the two arrays are already sorted can reduce runtime.