Skip to content

Commit 8e4c6d4

Browse files
. R extract method does_rule_apply
Co-Authored-By: Joel Silberman <42779942+jcs-instructor@users.noreply.github.com> Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
1 parent 289824b commit 8e4c6d4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
161 Bytes
Binary file not shown.

katas/fizzbuzz_with_db_2/fizzbuzz.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ def __init__(self, word, divisor):
1919
# print(f"An error occurred while fetching rules from MongoDB: {e}")
2020
# return rules
2121

22-
def fizz_buzz(i, rules=None):
22+
def does_rule_apply(number, divisor):
23+
return number % divisor == 0 # Later: if we want 'contains' functionality, add: `or str(divisor) in str(num)`
24+
25+
def fizz_buzz(number, rules=None):
2326
# TODO: Use default rules from MongoDB if no rules are specified
2427
# if rules is None:
2528
# rules = default_rules_from_db
2629
output = []
2730
for rule in rules:
28-
if i % rule.divisor == 0: # Later: if we want contains functionality, add: or str(rule.divisor) in str(i)
31+
if does_rule_apply(number, rule.divisor):
2932
output.append(rule.word)
30-
return ''.join(output) if output else str(i)
33+
return ''.join(output) if output else str(number)
3134

3235
# TODO: DB work:
3336

0 commit comments

Comments
 (0)