# My JavaScript solution

• ``````/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number}
*/
var findMedianSortedArrays = function(nums1, nums2) {
var nums3 = [];
if(nums1.length === 0){
nums3 = nums2;
}
if(nums2.length === 0){
nums3 = nums1;
}
if(nums1.length !== 0 && nums2.length !== 0){
nums3 = (nums1.concat(nums2)).sort(function(a,b){return a - b});
}
if(nums3.length % 2 == 0){
return (nums3[parseInt(nums3.length/2) - 1] + nums3[parseInt(nums3.length/2)]) / 2;
}else{
return nums3[parseInt(nums3.length/2)];
}
};
``````

• @Hunlongyu

new code

``````/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number}
*/
var findMedianSortedArrays = function(nums1, nums2) {
var nums3 = [], n1l = nums1.length, n2l = nums2.length, n3l;
if(n1l === 0){
nums3 = nums2;
}
if(n2l === 0){
nums3 = nums1;
}
if(n1l !== 0 && n2l !== 0){
nums3 = (nums1.concat(nums2)).sort(function(a,b){return a - b});
}
n3l = nums3.length;
if(n3l % 2 === 0){
return (nums3[n3l/2 - 1] + nums3[n3l/2]) / 2;
}else{
return nums3[parseInt(n3l/2)];
}
};
``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.