Pages

August 1, 2013

Check if value is greater than or equal to an array of values

Simple but useful math function: check if a value is >= than a bunch of values.


/** Check whether a value is greater 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 greater than or equal to all other values, false otherwise.
 @see isValue:greaterThanValues:
 @see isValue:lesserThanValues:
 @see isValue:lesserThanOrEqualToValues:

 */
+ (BOOL)isValue:(CGFloat)val greaterThanOrEqualToValues:(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 or equal to an array of values

No comments:

Post a Comment