Solution:
Pictorial Represantation:
Step 1) first of all Create a median function that takes two arrays.
Step 2) Marge both arrays in one using the javascript Spread operator(...) and Sort the array elements in ascending order using sort() methods.
Step 3): Now divide the sorting array length by 2 and store it in any variable (let half)
Step 4) Take now floor value of 'half' using Math. floor()
Step 5) Now check half % 2 == 0 is true which means it is even, then return the average of two middle elements
Step 6) if half % 2 == 0 is false which means it is odd, then return the middle element of the sorted array.
Example:
0 Comments
Thank you for Comment