Skip to content

Max-Min-Identity

Sourcery rule id: max-min-identity

Description

Use max/min instead of if statement

Before

if (a < b) {
  c = a
} else {
  c = b
}

After

c = Math.min(a, b)

Explanation

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.