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
Using fold method with dart:math library
Example:
// Main function
void main() {
// Creating a geek list
var geekList = [121, 12, 33, 14, 3];
// Declaring and assigning
// the largestGeekValue and smallestGeekValue
// Finding the smallest and
// largest value in the list
var smallestGeekValue = geekList.fold(geekList[0],min);
var largestGeekValue = geekList.fold(geekList[0],max);
// Printing the values
print("Smallest value in the list : $smallestGeekValue");
print("Largest value in the list : $largestGeekValue");
}
Output:
Smallest value in the list : 3
Largest value in the list : 121
Answer from : https://www.geeksforgeeks.org/dart-finding-minimum-and-maximum-value-in-a-list/