ios 数组最大值,最小值,平均值,和的快速算法

时间:2021-02-02 15:10:56

NSArray *testArray = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0",@"10",nil];
    
    NSNumber *sum1 = [testArray valueForKeyPath:@"@sum.floatValue"];
    
    NSNumber *avg1 = [testArray valueForKeyPath:@"@avg.floatValue"];
    NSNumber* max1=[testArray valueForKeyPath:@"@max.floatValue"];
    NSNumber* min1=[testArray valueForKeyPath:@"@min.floatValue"];
    NSLog(@"%@ %@ %@ %@",sum1,avg1,max1,min1);

得到结果在右下角控制台打印出来:

ios 数组最大值,最小值,平均值,和的快速算法