Median of Two Sorted Arrays

updated Oct 8, 2021created Oct 8, 2021
js
/** * @param {number[]} nums1 * @param {number[]} nums2 * @return {number} */ var findMedianSortedArrays = function(nums1, nums2) { let newNum = [...nums1, ...nums2]; newNum.sort(function(a, b) { return a - b; }); console.log("newNum:", newNum); let half = (newNum.length / 2) | 0; console.log("half:", half); if (newNum.length % 2) { return newNum[half] } return (newNum[half-1] + newNum[half]) / 2; };