Skip to content

Refactor : getValidSurveys to Reduce Cognitive Complexity #213

@ankitkumar748846

Description

@ankitkumar748846

Description:

The function getValidSurveys currently has a high cognitive complexity due to multiple nested if conditions, redundant checks, and an imperative loop structure. Refactoring this function will improve readability, maintainability, and efficiency while keeping the logic intact.

Problems Identified:

  • High Cognitive Complexity due to multiple nested conditions.
  • Imperative Looping (for loop) instead of using .filter(), making it harder to read.
  • Repeated Condition Checks, which can be simplified into a single return statement.

Benefits of Refactoring:

  • Improves Readability – The logic is clearer and easier to follow.
  • Reduces Nesting – Removes deep if conditions, making it more concise.
  • Uses Functional Approach (.filter()) – More idiomatic and efficient in JavaScript.
  • Easier to Maintain – Future modifications will be simpler with reduced complexity.

Current Implementation:

Image

Proposed Refactored Version:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions