Replace imperative with declarative code
Rewrite imperative loops as declarative map/filter/reduce pipelines using method chaining and expression-based patterns. Prioritises clarity over cleverness.
Preview
Copy prompt
Refactor the following imperative [Language] code to a more declarative style: [Paste code]. Replace explicit for and while loops with map, filter, reduce, or their language-native equivalents. Favour method chaining for sequential transforms and expression-based patterns over statement-based control flow. Prioritise clarity and readability over compactness, and add a comment explaining the overall data transformation at the top of the refactored function.
More
Refactoring
Prompts
