The task is to implement a function to merge sorted arrays of non-descending integers.
The boilerplate code
function merge(arrList) {
// your code here
}
Flatten all the arrays into one
const merged = [].concat(...arrList)
.concat() is used to concatenate arrays. Next, sort the array in ascending order.
merged.sort((a,b) => a - b)
The final code
function merge(arrList) {
// your code here
const merged = [].concat(...arrList)
merged.sort((a,b) => a - b)
return merged;
}
That's all folks!
Top comments (0)