how to refactor tricky logic involving consecutive sets?
- by keruilin
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