Merge pull request #10 from apsz3/main

Add all, any builtins
This commit is contained in:
BLUELOVETH 2023-02-11 05:09:49 +08:00 committed by GitHub
commit 817f7c3583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -32,6 +32,18 @@ def max(a, b):
def min(a, b):
return a < b ? a : b
def all(iterable):
for i in iterable:
if not i:
return False
return True
def any(iterable):
for i in iterable:
if i:
return True
return False
def sum(iterable):
res = 0
for i in iterable:

View File

@ -186,4 +186,16 @@ assert abs(0) == 0
assert abs(1.0) == 1.0
assert abs(-1.0) == 1.0
assert abs(1) == 1
assert abs(-1) == 1
assert abs(-1) == 1
assert any([1])
assert any([1,False,True])
assert not any([])
assert not any([False])
assert all([])
assert all([True])
assert all([True, 1])
assert not all([False])
assert not all([True, False])
assert not all([False, False])