Skip to content

Commit 33a85f6

Browse files
committed
feat(and): add and function
1 parent 0d059ab commit 33a85f6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test from "ava";
22
import {
3+
and,
34
asyncIterable,
45
average,
56
contains,
@@ -270,3 +271,9 @@ test("average", async t => {
270271
t.is(await average(asyncIterable([1, 2, 3, 2])), 2);
271272
t.is(await average(asyncIterable([])), null);
272273
});
274+
275+
test("and", async t => {
276+
t.true(await and(asyncIterable([true, true, true])));
277+
t.false(await and(asyncIterable([true, false, true])));
278+
t.true(await and(asyncIterable([])));
279+
});

index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,3 +847,9 @@ export async function average(iterable: AsyncIterableLike<number>): Promise<numb
847847
}
848848

849849
export const asyncAverage = average;
850+
851+
export async function and(iterable: AsyncIterableLike<boolean>): Promise<boolean> {
852+
return (await findIndex(iterable, element => !element)) == null;
853+
}
854+
855+
export const asyncAnd = and;

0 commit comments

Comments
 (0)