Skip to content

Optimize calculateFreebuffStreak to single-pass iteration - #1260

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/calculate-streak-single-loop
Open

Optimize calculateFreebuffStreak to single-pass iteration#1260
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/calculate-streak-single-loop

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Optimize the calculateFreebuffStreak function in common/src/util/freebuff-streak.ts to use a single pass instead of two iterations.

Bug Description

The function iterated through usageDates twice:

  1. Once with filter() to build the usageDateSet
  2. Once with reduce() to find lastUsageDate

This is O(2n) when it could be O(n) by combining both operations in a single loop.

Fix

Combined both operations into one loop, building the set and tracking the latest date simultaneously. This is more efficient and clearer in intent.

Testing

All existing tests pass (14/14).

Files Changed

  • common/src/util/freebuff-streak.ts - Single-pass iteration optimization

Scope

This change only touches common/src/util/freebuff-streak.ts (a single file in the approved common/ area).

The function iterated through usageDates twice:
1. Once with filter() to build the usageDateSet
2. Once with reduce() to find lastUsageDate

This is O(2n) when it could be O(n) by combining both operations in a single loop.

Combined both operations into one loop, building the set and tracking the latest
date simultaneously. This is more efficient and clearer in intent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant