if(pf[i].length > highest){
highest = pf[i].length;
}
What is the most efficient way of conveying the statement above?
Math.max
function returns the largest of zero or more numbers.
highest = Math.max(pf[i].length, highest)
You can use Math.max
to get the maximum of the two values, highest
and pf[i].length
.
highest = Math.max(highest, pf[i].length);
Or, you can also use ternary operator.
highest = pf[i].length > highest ? pf[i].length : highest;
// ^^^^^^^^^^^^^^^^^^^^^^ Condition
// ^^^^^^^^^^^^ Execute when True
// ^^^^^^^ Execute when False
The value from Ternary operation is returned and is set to the variable highest
.
Try inline IF statement (ternary operator):
highest = pf[i].length > highest ? pf[i].length : highest;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With