src/lib/utils.js
// Given an array of numbers it calculates the median value.
Given an array of numbers it calculates the median value.
Given an array of numbers it calculates the median value .
function median(arr) {
  arr = arr.slice(0);
  arr.sort((a, b) => a - b);
  const half = Math.floor(arr.length / 2);
  if (arr.length % 2) {
    return arr[half];
  } else {
    return (arr[half - 1] + arr[half]) / 2.0;
  }
}
function median ( arr ) { arr = arr . slice ( 0 ) ; arr . sort ( ( a , b ) => a - b ) ; const half = Math . floor ( arr . length / 2 ) ; if ( arr . length % 2 ) { return arr [ half ] ; } else { return ( arr [ half - 1 ] + arr [ half ] ) / 2.0 ; } }
Given an array of numbers it calculates the median value.
Given an array of numbers it calculates the median value .