Answers for "how to merge two unsorted arrays"

3

Write a function that takes in two sorted arrays and returns a new array with all elements sorted not using array method sort.

// const newSortArrays = (arr1, arr2) => {
//     let output = [];
//     while (arr1.length && arr2.length) {
//        if (arr1[0] < arr2[0]) 
//         output.push(arr1[0] < arr2[0] ? arr1.shift() : arr2.shift())
//     }
//     return [...output, ...arr1, ...arr2]
// }
Posted by: Guest on November-17-2019
0

how to merge two unsorted arrays

1
2
3
4
Posted by: Guest on May-21-2020
0

write a function that takes in 2 arrays , merges them together an then return the new array sorted

// const twoArraysSorted = (arr) => {
//     let copy = [...];
//     copy.sort((a,b) => a-b).map(el=> el*2)
//     return arr
// }
Posted by: Guest on November-17-2019

Browse Popular Code Answers by Language