Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* @returns The median of the given data set.
*/
export const median = (dataSet: number[]): number => {
+ if (Array.isArray(dataSet) && dataSet.length === 0) {
+ return 0
+ }
if (Array.isArray(dataSet) && dataSet.length === 1) {
return dataSet[0]
}
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]