Pattern: Parameter only used in recursive call
Issue: -
Function parameters that are only used in recursive calls without any other purpose likely indicate a mistake. These parameters increase complexity without adding value since they're just passed through unchanged.
Example of incorrect code:
function process(data, unused) {
if (data.length === 0) return;
return process(data.slice(1), unused);
}
const calc = (x, extra) => {
return x > 0 ? calc(x - 1, extra) : 0;
};
Example of correct code:
function process(data) {
if (data.length === 0) return;
return process(data.slice(1));
}
const calc = (x) => {
return x > 0 ? calc(x - 1) : 0;
};