• 0

Programming shorthands / tricks


Different ways to track the max value while iterating over different values

We can use if, ternary operator or Math.max function as shown below.

if (val > max) {
  max = val
}

max = val > max ? val : max

max = Math.max(max, val)