In search of the smartest, most efficient and readable way to do the below:
int one = 1, two = 2;
int larger = one < two?two:one;
I prefer(or a variadic version of the below):
int largest(one,two){return one<two?two:one;}
int larger = largest(one,two);
But dart has no inline or macro.
With List:
var nums = [51,4,6,8];
nums.sort();
in largest = nums.last
Or(Thank you, Günter Zöchbauer):
print([1,2,8,6].reduce(max));
Using math library:
import 'dart:math';
int largest = max(21,56);
Probably the best, but how efficient is max in comparison to the first approach?
Why the question?
With the first approach I must check comparisons are done right for each of them;hundreds of them sometimes. With the second, only one function to verify, but hundreds of function calls.