Mean and Median
const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length;
const getMedian = (array) => { const sorted = array.toSorted((a, b) => a - b); const median = sorted.length % 2 === 0 ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) : sorted[Math.floor(sorted.length / 2)]; return median; }
Wed, 12 Feb 2025, 10:27 pm