Skip to content

Improve readability of count validation in lazy-response-ads - #1228

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/lazy-response-ads-validation
Open

Improve readability of count validation in lazy-response-ads#1228
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/lazy-response-ads-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Improve code readability by extracting a complex ternary expression into a separate variable.

Change

The original code had a nested ternary inside Math.min/Math.max:

const count = Number.isFinite(params.count)
  ? Math.min(MAX_RESPONSE_AD_POOL_SIZE, Math.max(0, Math.floor(params.count)))
  : 0

This was hard to read. Extracted the validation into a separate variable:

const safeCount = Number.isFinite(params.count) ? params.count : 0
const count = Math.min(MAX_RESPONSE_AD_POOL_SIZE, Math.max(0, Math.floor(safeCount)))

Testing

All existing tests pass (5/5).

Files Changed

  • common/src/util/lazy-response-ads.ts - Refactored count validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The original code used a ternary inside Math.min/Math.max which was hard to read.
Extracted the Number.isFinite check into a separate variable for clarity.

This is a pure refactor with no behavioral change - the logic is identical.
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