An opaque, convoluted, or hand-rolled algorithm where a clearer and well-known pattern (often library-provided) produces the same outputs.
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;}
Future readers spend cycles decoding the bespoke version; correctness arguments stay local to this implementation; performance characteristics are unknown.
Swapping algorithms wholesale forfeits behavioral safety — characterize the function with tests at every relevant input boundary before substituting.
Future maintainers read the well-known pattern instead of decoding the bespoke implementation; performance and correctness usually improve.
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.