LLM Prompts

Code Refactoring Assistant

Refactors code for improved readability, efficiency, and maintainability.

The method

Use this prompt by pasting it directly into your LLM interface. Provide the code you wish to refactor and specify the desired improvements. Best used for improving readability, efficiency, and maintainability. Ensure code is syntactically correct.

The prompts

Prompt 1
Please analyze the following code and refactor it to improve its readability, efficiency, and maintainability. Focus on reducing complexity, eliminating redundancy, and adhering to best practices. Provide the refactored code along with a brief explanation of the changes made and the reasoning behind them. Consider using appropriate design patterns where applicable. The code is:

```python
def calculate_average(numbers):
sum = 0
count = 0
for number in numbers:
sum += number
count += 1
if count == 0:
return 0
else:
return sum / count
```
Prompt 2
Refactor the following JavaScript code to enhance its performance and reduce potential errors. Consider using modern ES6+ features and optimizing for speed. Explain the changes you make.

```javascript
function findMax(arr) {
var max = arr[0];
for (var i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
```