mirror of
https://github.com/ossu/computer-science.git
synced 2025-04-02 02:45:36 -04:00
add accumulate and filtered-accumulate patterns in 1.1.3
This commit is contained in:
parent
62b7aa9967
commit
575e44c837
Binary file not shown.
@ -20,4 +20,17 @@ for i in range(0, len(items), 1):
|
||||
if items[i] % 2 == 0:
|
||||
count += 1
|
||||
|
||||
# The accumulate pattern
|
||||
total = 0
|
||||
for i in range(0, len(items), 1):
|
||||
total += items[i]
|
||||
|
||||
# The filtered-accumulate pattern
|
||||
def sumEvens(items):
|
||||
total = 0
|
||||
for i in range(0, len(items), 1):
|
||||
if items[i] % 2 == 0:
|
||||
total += items[i]
|
||||
return total
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user