Without knowing the range and when the array is unordered, so there is no need to sort the array ascendingly and get the first element
So I have this method:
- (NSInteger) lowestNumberInArray:(NSArray *)arrayOfNumbers {
Parameter: array of NSNumbers
Return: The lowest number in the array as an NSInteger
I am thinking of a for loop that loops through the array, once the lowest number is found then store that number into a NSInteger. However, I don't know the range of the array values aka I don't know what's my biggest and lowest number. I looked into NSArray and NSMutableArray documentation and didn't find any method that I can use to return the smallest value. Your help will be greatly appreciated! :)
- (NSInteger) lowestNumberInArray:(NSArray *)arrayOfNumbers {
smallest = equalBiggestNumber;
for (NSInteger i = 0; i < arrayOfNumbers.count; i++) {
if (arrayOfNumbers[i] < smallest) {
smallest = arrayOfNumbers[i];
}
return 0;
}