Pages

July 29, 2013

Check if value is lesser than an array of values

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


/** Check whether a value is tightly lesser 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 lesser than all other values, false otherwise.
 @see isValue:greaterThanValues:
 @see isValue:greaterThanOrEqualToValues:
 @see isValue:lesserThanOrEqualToValues:

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

No comments:

Post a Comment