import type { Falsy } from '@js-utils-kit/types'; /** * Removes all falsy values from an array. * * Falsy values include: `false`, `null`, `0`, `""`, `undefined`, and `NaN`. * * @returns A new array with all falsy values removed * * @example * ```ts * compact([0, 1, false, 2, '', 3, null]); * // [1, 2, 3] * * compact(['a', '', 'b', undefined]); * // ['a', 'b'] * ``` */ export function compact( /** * A list of elements to compact */ array: readonly T[], ): Exclude[] { return array.filter( (value): value is Exclude => Boolean(value) && !Number.isNaN(value), ); }