Simple but useful math function: check if a value is > than a bunch of values.
/** Check whether a value is tightly greater than some values.
@param val Float value to test.
@param arr Array of all numbers to compare with.
@return Returns true if given number is tightly greater than all other values, false otherwise.
@see isValue:greaterThanOrEqualToValues:
@see isValue:lesserThanValues:
@see isValue:lesserThanOrEqualToValues:
*/
+ (BOOL)isValue:(CGFloat)val greaterThanValues:(NSArray *)arr {
for (NSInteger i=0; i<[arr count]; i++) {
if (val < [[arr objectAtIndex:i] floatValue]) {
return NO;
}
}
return YES;
}
Download the ready-for-use source file (.m) of Check if value is greater than an array of values
No comments:
Post a Comment