Simple but useful math function: check if a value is <= than a bunch of values.
/** Check whether a value is lesser than or equal to some values.
@param val Float value to test.
@param arr Array of all numbers to compare with.
@return Returns true if given number is lesser than or equal to all other values, false otherwise.
@see isValue:greaterThanValues:
@see isValue:greaterThanOrEqualToValues:
@see isValue:lesserThanValues:
*/
+ (BOOL)isValue:(CGFloat)val lesserThanOrEqualToValues:(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 lesser than or equal to an array of values
No comments:
Post a Comment