-
-
Save galileoguzman/8e9f83b9e679579a8c25cde39449c0e1 to your computer and use it in GitHub Desktop.
Gist file for Lidia from Incode
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
@interface SolutionClass : NSObject | |
-(NSArray*)uniqueEntriesIn:(NSArray*) list lessThan:(NSNumber*) maxValue; | |
-(NSDictionary<NSString*, NSNumber*>*)countClassesIn:(NSArray*)list; | |
@end | |
@implementation SolutionClass | |
-(NSArray*)uniqueEntriesIn:(NSArray*) list lessThan:(NSNumber*) maxValue | |
{ | |
NSMutableArray* arResult = [[NSMutableArray alloc] init]; | |
int count = (int) list.count; | |
for(int i = 0; i < count; i++){ | |
if([list[i] isKindOfClass:[NSNumber class]]){ | |
NSNumber* item = (NSNumber*) list[i]; | |
if (![arResult containsObject:item]) { | |
[arResult addObject:item]; | |
} | |
} | |
} | |
NSSortDescriptor* order = [NSSortDescriptor sortDescriptorWithKey: @"self" | |
ascending: YES]; | |
NSArray* result = [arResult sortedArrayUsingDescriptors: [NSArray arrayWithObject: order]]; | |
return result; | |
} | |
-(NSDictionary<NSString*, NSNumber*>*)countClassesIn:(NSArray*)list{ | |
int count = (int) list.count; | |
int countNumbers = 0; | |
int countStrings = 0; | |
for(int i = 0; i < count; i++){ | |
if([list[i] isKindOfClass:[NSNumber class]]){ | |
countNumbers = countNumbers + 1; | |
}else if([list[i] isKindOfClass:[NSString class]]){ | |
countStrings = countStrings + 1; | |
} | |
} | |
NSDictionary *results = @{ | |
@"NSNumber": [NSNumber numberWithInteger:countNumbers], | |
@"NSString": [NSNumber numberWithInteger:countStrings], | |
}; | |
return results; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment