# Sparc Refinement Example 4 Complexity Reduction

> Sub-skill of sparc-refinement: Example 4: Complexity Reduction.

- Skill: `vamseeachanta/sparc-refinement-example-4-complexity-reduction` (Agent Skill)
- Install (CLI): `npx skillmds@latest add vamseeachanta/sparc-refinement-example-4-complexity-reduction`
- Raw SKILL.md: https://api.skillmd.com/api/skills/vamseeachanta/sparc-refinement-example-4-complexity-reduction/raw
- Safety review: PASS (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: vamseeachanta (https://skillmd.com/u/vamseeachanta)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/vamseeachanta/sparc-refinement-example-4-complexity-reduction

---


# Example 4: Complexity Reduction

## Example 4: Complexity Reduction


```typescript
// Bad: Cyclomatic complexity = 7
function processUser(user: User): void {
  if (user.age > 18) {
    if (user.country === 'US') {
      if (user.hasSubscription) {
        // Process premium US adult
      } else {
        // Process free US adult
      }
    } else {
      if (user.hasSubscription) {
        // Process premium international adult
      } else {
        // Process free international adult
      }
    }
  } else {
    // Process minor
  }
}

// Good: Cyclomatic complexity = 2
function processUser(user: User): void {
  const processor = getUserProcessor(user);
  processor.process(user);
}

function getUserProcessor(user: User): UserProcessor {
  const type = getUserType(user);
  return ProcessorFactory.create(type);
}
```

