add accumulate and filtered-accumulate patterns in 1.1.3
This commit is contained in:
1 parent
62b7aa9967
commit
575e44c837
2 files changed
+13
No files matched your search
BIN
Binary file not shown.
+13
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user