Skip to content

Commit

Permalink
Meetup : sync expected test results and input data with problem-speci…
Browse files Browse the repository at this point in the history
…fications. (#1803)
  • Loading branch information
BethanyG authored and cmccandless committed May 30, 2019
1 parent 422773a commit 36756fa
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 108 deletions.
19 changes: 10 additions & 9 deletions exercises/meetup/example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from calendar import Calendar


def meetup_day(year, month, day_of_the_week, which):
def meetup(year, month, week, day_of_week):
candidates = [date
for date in Calendar().itermonthdates(year, month)
if date.month == month
if date.strftime('%A') == day_of_the_week]
return _choice(which)(candidates)
if date.strftime('%A') == day_of_week]
return _choice(week)(candidates)


def _choice(which):
if which == 'teenth':
return lambda dates: next(d for d in dates if 13 <= d.day <= 19)
def _choice(week):
if week == 'teenth':
return lambda dates: next(date for date in dates if
13 <= date.day <= 19)

ix = -1 if (which == 'last') else (int(which[0]) - 1)
day = -1 if (week == 'last') else (int(week[0]) - 1)

def _func(dates):
if ix < len(dates):
return dates[ix]
if day < len(dates):
return dates[day]
raise MeetupDayException('day does not exist')
return _func

Expand Down
2 changes: 1 addition & 1 deletion exercises/meetup/meetup.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def meetup_day(year, month, day_of_the_week, which):
def meetup(year, month, week, day_of_week):
pass
Loading

0 comments on commit 36756fa

Please sign in to comment.