How do you get the min and max values of a List in Dart.
[1, 2, 3, 4, 5].min //returns 1
[1, 2, 3, 4, 5].max //returns 5
I'm sure I could a) write a short function or b) copy then sort the list and select the last value,
but I'm looking to see if there is a more native solution if there is any.
You can now achieve this with an
extension
as of Dart 2.6:Inefficient way:
Without importing the 'dart: math' library:
Assuming the list is not empty you can use Iterable.reduce :
If you don't want to import
dart: math
and still wants to usereduce
: