Flatten deeply nested conditionals
Replace deeply nested if/else chains with guard clauses, early returns, or a lookup table. Preserves identical external behaviour with a complexity comparison.
Preview
Copy prompt
The following function has several layers of deeply nested if/else chains that make it hard to read and test: [Paste code]. Refactor it by applying guard clauses for early returns, extracting complex conditions into well-named predicate functions, or replacing a chain of conditionals with a lookup table or strategy pattern where appropriate. The external behaviour must remain identical. Show the refactored version and a before-and-after cyclomatic complexity estimate.
More
Refactoring
Prompts
