|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
630 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | type Falsey = false | null | 0 | 0n | '' | undefined;
|
|---|
| 2 | /**
|
|---|
| 3 | * Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.
|
|---|
| 4 | *
|
|---|
| 5 | * @template T - The type of elements in the array.
|
|---|
| 6 | * @param {ArrayLike<T | Falsey> | null | undefined} arr - The input array to remove falsey values.
|
|---|
| 7 | * @returns {Array<Exclude<T, false | null | 0 | 0n | '' | undefined>>} - A new array with all falsey values removed.
|
|---|
| 8 | *
|
|---|
| 9 | * @example
|
|---|
| 10 | * compact([0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
|
|---|
| 11 | * Returns: [1, 2, 3, 4, 5]
|
|---|
| 12 | */
|
|---|
| 13 | declare function compact<T>(arr: ArrayLike<T | Falsey> | null | undefined): T[];
|
|---|
| 14 |
|
|---|
| 15 | export { compact };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.