remeda
Version:
A utility library for JavaScript and Typescript.
48 lines (47 loc) • 1.96 kB
text/typescript
import { IterableContainer } from "./IterableContainer-JENOIFLG.cjs";
//#region src/median.d.ts
type Median<T extends IterableContainer<number>> = (T extends readonly [] ? never : number) | (T extends readonly [unknown, ...Array<unknown>] ? never : undefined);
/**
* Returns the median of the elements of an array.
*
* Only `number` arrays are supported, as `bigint` is unable to represent fractional values.
*
* IMPORTANT: The result for empty arrays would be `undefined`, regardless of
* the type of the array. This approach improves type-checking and ensures that
* cases where `NaN` might occur are handled properly. To avoid adding this to
* the return type for cases where the array is known to be non-empty you can use
* `hasAtLeast` or `isEmpty` to guard against this case.
*
* @param data - The array of numbers.
* @signature
* R.median(data);
* @example
* R.pipe([6, 10, 11], R.median()); // => 10
* R.median([]); // => undefined
* @dataFirst
* @category Number
*/
declare function median<T extends IterableContainer<number>>(data: T): Median<T>;
/**
* Returns the median of the elements of an array.
*
* Only `number` arrays are supported, as `bigint` is unable to represent fractional values.
*
* IMPORTANT: The result for empty arrays would be `undefined`, regardless of
* the type of the array. This approach improves type-checking and ensures that
* cases where `NaN` might occur are handled properly. To avoid adding this to
* the return type for cases where the array is known to be non-empty you can use
* `hasAtLeast` or `isEmpty` to guard against this case.
*
* @signature
* R.median()(data);
* @example
* R.pipe([6, 10, 11], R.median()); // => 10
* R.pipe([], R.median()); // => undefined
* @dataLast
* @category Number
*/
declare function median(): <T extends IterableContainer<number>>(data: T) => Median<T>;
//#endregion
export { median };
//# sourceMappingURL=median-LwOsNuSJ.d.cts.map