Skip to content

Commit

Permalink
More functions (#4)
Browse files Browse the repository at this point in the history
- Add compact
- Fix
- Fix
- Fix
- Fix
  • Loading branch information
raviqqe committed Nov 10, 2023
1 parent 520b1f1 commit 59b62d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/compact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { it, expect } from "vitest";
import { compact } from "./compact.js";

for (const [xs, y] of [
[[0], []],
[[""], []],
[[undefined], []],
[[null], []],
[[false], []],
[
[-1, 0, 1],
[-1, 1],
],
] satisfies [unknown[], unknown[]][]) {
it(`finds the last element in an array ${JSON.stringify(xs)}`, () => {
const zs: unknown[] = xs;

expect(compact(zs)).toEqual(y);
});
}
4 changes: 4 additions & 0 deletions src/compact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const compact = <T>(
xs: T[],
): Exclude<T, 0 | "" | false | null | undefined>[] =>
xs.filter(Boolean) as Exclude<T, 0 | "" | false | null | undefined>[];
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./compact.js";
export * from "./identity.js";
export * from "./last.js";
export * from "./once.js";
Expand Down

0 comments on commit 59b62d8

Please sign in to comment.