将两个有序数组合并为一个有序数组
1 function sortSTB(arr1,arr2){ 2 let index1 = 0,index2 = 0; 3 let result = []; 4 while(index1 !== arr1.length && index2 !== arr2.length){ 5 if(arr1[index1] <= arr2[index2]){ 6 result.push(arr1[index1]); 7 index1++; 8 }else{ 9 result.push(arr2[index2]); 10 index2++; 11 } 12 } 13 if(index1 === arr1.length){ 14 result = result.concat(arr2.slice(index2)); 15 }else{ 16 result = result.concat(arr1.slice(index1)); 17 } 18 19 return result; 20 }