Day - 54
Assalamu alaykum, everyone! How are you today? Today I am going to share the solutions of 54th day of my coding challenge!
/*
?* @param {number[]} nums1
?* @param {number[]} nums2
?* @return {number}
?*/
var findMedianSortedArrays = function (nums1, nums2) {
? const val = [...nums1, ...nums2].sort(function (a, b) {
? ? return a - b;
? });
? if (val.length % 2 !== 0) {
? ? const median = Math.floor(val.length / 2);
? ? return val[median].toFixed(4);
? } else if (val.length % 2 === 0) {
? ? const med1 = val[val.length / 2 - 1];
? ? const med2 = val[val.length / 2];
? ? const median = (med1 + med2) / 2;
? ? return median.toFixed(4);
? }
};
I think it is an easy way of getting median of 2 arrays. Then, If you have any solutions that better than mine, let's share it with me and your friends as well.
Already, we passed half of my challenge. We have 46 days and we will successfully complete this challenge! If I think about it, I can not explain how I feel myself. So, let's wait. It will be fine.
Thanks for your attention as well. I am glad to post today's article. I am glad to give something. See you!