Symptom

An opaque, convoluted, or hand-rolled algorithm where a clearer and well-known pattern (often library-provided) produces the same outputs.

Goal

An opaque or convoluted algorithm gets replaced by a clearer one (often from a library or well-known pattern) that produces the same outputs.

Before the refactoring

function found(people, n) {
for (const p of people) if (p.name === n) return p;
return null;
}

After the refactoring

function found(people, n) {
return people.find(p => p.name === n) ?? null;
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Future readers spend cycles decoding the bespoke version; correctness arguments stay local to this implementation; performance characteristics are unknown.

Tradeoff

Swapping algorithms wholesale forfeits behavioral safety — characterize the function with tests at every relevant input boundary before substituting.

Relief

Future maintainers read the well-known pattern instead of decoding the bespoke implementation; performance and correctness usually improve.

Trap

Swapping algorithms without characterizing every input boundary the original handled — including the off-by-one cases the original quietly got right that the substitute might get differently.