rewrite ternary expression as simple Math.min call (yes, the ternary expression as written is equivalent to min, not max, despite the variable being called max. I'll leave that fix up to the original author).