Parameterize Function

Removes smells
Symptom

Two or more near-identical functions that differ only in literal values — `tenPercentRaise(person)` and `fivePercentRaise(person)` differ only in 1.10 vs 1.05.

Goal

Two near-identical functions that differ only in literal values combine into one with a parameter.

Before the refactoring

function tenPercentRaise(person) { person.salary *= 1.10; }
function fivePercentRaise(person) { person.salary *= 1.05; }

After the refactoring

function raise(person, factor) { person.salary *= 1 + factor; }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Bug fixes must land in every variant; new variants are new functions; the shared shape isn't expressed anywhere.

Tradeoff

If the variations are conceptually different operations, one parameterized function will accumulate flags and special cases — keep them separate then.

Relief

One canonical implementation; new variations are new parameter values, not new functions.

Trap

Parameterizing functions whose variations are conceptually different operations — the parameterized function accumulates flags and special cases that overwhelm the original simplicity.