Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 532 Bytes

bad-min-max-func.md

File metadata and controls

21 lines (15 loc) · 532 Bytes

Pattern: Invalid min/max clamp

Issue: -

Description

When using Math.min and Math.max for clamping values, the arguments must be in the correct order. Incorrect ordering can result in the function always returning the same constant value.

Examples

Example of incorrect code:

const value = Math.min(Math.max(100, x), 0);
const num = Math.max(1000, Math.min(0, x));

Example of correct code:

const value = Math.min(Math.max(0, x), 100);
const num = Math.max(0, Math.min(1000, x));