UNPKG

moy-fp

Version:
16 lines (13 loc) 356 B
import curry from '../Function/curry' import add from './add' /** * [Number] -> Number */ const median = curry( array => { const list = array.sort((a, b) => a - b), length = list.length return length === 0 ? NaN : length % 2 === 0 ? (list[length / 2] + list[length / 2 - 1]) / 2 : list[(length - 1) / 2] } ) export default median