You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionmerge(arr1,arr2){letresults=[];leti=0,j=0;while(i<arr1.length&&j<arr2.length){if(arr2[j]>arr1[i]){results.push(arr1[i])i++;}else{results.push(arr2[j]);j++;}}while(i<arr1.length){results.push(arr1[i])i++;}while(j<arr2.length){results.push(arr2[j])j++;}returnresults;}functionmergesort(input){//arrays of 0 or 1 elements are always sorted//decompose an array into smaller arrays (e.g. split in half, split again, get to single arrays. Then merge them together.)if(input.length<=1){returninput;}letmid=Math.floor(input.length/2)returnmerge(mergesort(input.slice(0,mid)),mergesort(input.slice(mid)))}
Implement merge sort.
The text was updated successfully, but these errors were encountered: