how to refactor tricky logic involving consecutive sets?
Posted
by keruilin
on Stack Overflow
See other posts from Stack Overflow
or by keruilin
Published on 2010-05-27T12:23:38Z
Indexed on
2010/05/27
12:41 UTC
Read the original article
Hit count: 268
The rule at work here is that users can be awarded badges for a streak of 10, 20, and 30. If the user has a streak over 30, such as 40 or 50, then the logic must be that it only awards a 10-streak badge for 40 and a 20-streak badge for 50, and so on.
def check_win_streak(streak)
badge = 10
while badge < badge::MAX_STREAK_BADGE_SIZE do # MAX_STREAK_BADGE_SIZE = 30
if streak < badge then
break
end
if (streak % badge == 0) then
award_streak_badge(badge)
end
badge += 10
end
end
© Stack Overflow or respective owner