Finding Max and Min
April 24th, 2006
Maybe this is common knowledge to some, but I just figured it out today, so I thought I'd share it.
Before, if I wanted to find the maximum or minimum number in a list of 3 or more numbers, I'd do something like:
max = Math.max(Math.max(Math.max(a, b), c), d); min = Math.min(Math.min(Math.min(a, b), c), d);
Math.min take as many arguments as you need, so you can do this instead:
max = Math.max(a, b, c, d); min = Math.min(a, b, c, d);