30秒学会 Dart 片段 – max
Returns the maximum value in a list of numbers.
Use Iterable.reduce()
in combination with max()
to find the maximum value.
代码实现
import 'dart:math';
num max(List<num> nums){
return nums.reduce(max);
}
使用样例
max([4, 6, 1, 2, 5]); // 6