Loading...
Loading...
Use when fixing, editing, changing, or debugging existing TypeScript code and keeping changes small and proportional to what was touched.
npx skill4agent add gosukiwi/clean-code-react clean-as-you-goclean-typescript// Asked to fix a bug in:
function proc(d: number[], x: number[], flag = false): number[] {
for (const i of d) {
if (i > 0) {
if (flag) { x.push(i * 1.0825); }
else { x.push(i); }
}
}
return x;
}
// Fix the bug AND leave it cleaner:
const TAX_RATE = 0.0825;
function processPositiveValues(values: readonly number[]): number[] {
return values.filter((value) => value > 0);
}
function processTaxablePositiveValues(values: readonly number[]): number[] {
return values.filter((value) => value > 0).map((value) => value * (1 + TAX_RATE));
}