Skip to content

Instantly share code, notes, and snippets.

@HeidiHansen
Created October 4, 2014 22:33
Show Gist options
  • Save HeidiHansen/c10493b331fffbbbb84f to your computer and use it in GitHub Desktop.
Save HeidiHansen/c10493b331fffbbbb84f to your computer and use it in GitHub Desktop.
FizzBuzz
- (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