return dataSet[0]
}
const sortedDataSet = dataSet.slice().sort((a, b) => a - b)
- if (sortedDataSet.length % 2 === 0) {
- return sortedDataSet[sortedDataSet.length / 2]
- }
return (
(sortedDataSet[(sortedDataSet.length - 1) >> 1] +
sortedDataSet[sortedDataSet.length >> 1]) /
describe('Utils test suite', () => {
it('Verify median computation', () => {
expect(median([])).toBe(0)
- const array0 = [0.08]
- expect(median(array0)).toBe(0.08)
- const array1 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
- expect(median(array1)).toBe(3.05)
+ expect(median([0.08])).toBe(0.08)
+ expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.05)
+ expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535)
})
it('Verify isPlainObject() behavior', () => {