I’m trying to use javascript to select the greater of two numbers. I know I can write an if statement, but I’m wondering if there’s some sort of Math operation or something to make this more efficient. Here’s how I’d do it with an if statement:
if (a > b) {
c = a;
}
else {
c = b;
}
You’re looking for the Max function I think….
This function will take more than two parameters as well:
If you have a array of arbitrary length to run through max, you can use
apply…OR if you’re using ES2015+ you can use spread syntax: