Skip to content

Instantly share code, notes, and snippets.

@theevo
Last active March 25, 2020 15:49
Show Gist options
  • Save theevo/364d31e8135332cafe93cc4bb24a2bcf to your computer and use it in GitHub Desktop.
Save theevo/364d31e8135332cafe93cc4bb24a2bcf to your computer and use it in GitHub Desktop.
//
// main.m
// Stretch Problem 4.3 - HighestNumberInArray
//
// Created by theevo on 3/25/20.
// Copyright © 2020 Theo Vora. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PlaygroundClass : NSObject
-(id) highestNumber:(NSArray *)inputArray;
@end
@implementation PlaygroundClass
-(id) highestNumber:(NSArray *)inputArray
{
NSSortDescriptor *sortOrder = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:NO];
NSArray *sortedArray = [inputArray sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
return [sortedArray firstObject];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *array = @[@1,@2,@3];
id i;
PlaygroundClass *playground = [[PlaygroundClass alloc]init];
i = [playground highestNumber:array];
NSLog(@"Highest number in %@ is... %@", array, i);
NSLog(@"Hello, World!");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment