1. 程式人生 > >iOS中求陣列元素中最大數、最小數以及求和、求平均值

iOS中求陣列元素中最大數、最小數以及求和、求平均值

直接上貨
NSArray *testArray = [NSArray arrayWithObjects:@”2.0”, @”2.3”, @”3.0”, @”4.0”, nil];
NSNumber *sum = [testArray valueForKeyPath:@”@sum.floatValue”];
NSNumber *avg = [testArray valueForKeyPath:@”@avg.floatValue”];
NSNumber *max = [testArray valueForKeyPath:@”@max.floatValue”];
NSNumber *min = [testArray valueForKeyPath:@”@min.floatValue”];