记录NSArray 快速求和、平均值、最大值、最小值
2017-04-21 本文已影响55人
CN_HarrySun
// 快速求和、平均值、最大值、最小值
NSArray *array = @[@1,@2,@3,@4,@5.3];
NSNumber *sum = [array valueForKeyPath:@"@sum.intValue"];
float avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
int max = [[array valueForKeyPath:@"@max.intValue"] intValue];
int min = [[array valueForKeyPath:@"@min.intValue"] intValue];
NSLog(@"%@ %f %d %d ",sum,avg,max,min);