Created
October 4, 2014 22:33
-
-
Save HeidiHansen/c10493b331fffbbbb84f to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *)getValuesBetweenNumber:(NSNumber *)startNumber andNumber:(NSNumber *)endNumber | |
{ | |
for (NSInteger i = [startNumber integerValue]; i <= [endNumber integerValue]; i++) | |
{ | |
[self.fizzBuzzArray addObject:@(i)]; | |
} | |
NSString *fizz = @"Fizz "; | |
NSString *buzz = @"Buzz "; | |
NSString *fizzBuzz = @"FizzBuzz "; | |
NSMutableString *result = [[NSMutableString alloc] init]; | |
for (NSInteger i = [startNumber integerValue]; i <= [self.fizzBuzzArray count]; i++) | |
{ | |
if (i %3 == 0 && i %5 == 0) | |
{ | |
[result appendString:fizzBuzz]; | |
} | |
else if (i % 5 == 0) | |
{ | |
[result appendString:buzz]; | |
} | |
else if (i % 3 == 0) | |
{ | |
[result appendString:fizz]; | |
} | |
else | |
{ | |
[result appendString:[NSString stringWithFormat:@"%ld ",(long)i]]; | |
} | |
} | |
NSLog(@"%@", result); | |
return self.fizzBuzzArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment