Skip to content

Max-Min-Identity

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Use max/min instead of if statement

if (a < b) {
c = a
} else {
c = b
}
c = Math.min(a, b)

We often need to work out the smallest or largest of two values, and the most readable way to do this is to use the built-in min and max functions. This results in a shorter and clearer way to achieve the same result.