1//#Source https://bit.ly/2neWfJ2
2const median = arr => {
3 const mid = Math.floor(arr.length / 2),
4 nums = [...arr].sort((a, b) => a - b);
5 return arr.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
6};
7console.log(median([5, 6, 50, 1, -5]));
8console.log(median([1, 2, 3, 4, 5]));
9