add accumulate and filtered-accumulate patterns in 1.1.3

pull/357/head
Eric Douglas 2014-05-22 18:44:30 -03:00
parent 62b7aa9967
commit 575e44c837
2 changed files with 13 additions and 0 deletions

View File

@ -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