find median values from array in javascript - Stack Overflow

PHOTO EMBED

Thu Dec 02 2021 23:29:42 GMT+0000 (UTC)

Saved by @tolanisirius #javascript

function median(arr) {
    arr = [...arr].sort((a, b) => a - b);
    return (arr[arr.length - 1 >> 1] + arr[arr.length >> 1]) / 2;
}
content_copyCOPY

Array methods

https://stackoverflow.com/questions/25305640/find-median-values-from-array-in-javascript-8-values-or-9-values