Sha256: a5eeaf60e14d9b997609c9656e78ba20237ad92e80f64074849b8fe2a211c693

Contents?: true

Size: 1.78 KB

Versions: 59

Compression:

Stored size: 1.78 KB

Contents

#import "SublistExample.h"

@implementation SublistExample

+(NSString*)classifierForFirstList:(NSArray *)firstArray andSecondList:(NSArray *)secondArray{
    
    if([firstArray isEqualToArray:secondArray]){
        
        return @"equal";
    
    }else if(firstArray.count == 0 || secondArray.count == 0){
        
        if(firstArray.count == 0){
            
            return @"sublist";
        }
        
        return @"superlist";
    
    }else if(firstArray.count != secondArray.count){
        
        int i = 0;
        int count = 0;
        NSMutableArray *smallerArray = [NSMutableArray array];
        
        int iterations = 0;
        iterations = MAX((int)firstArray.count, (int)secondArray.count) - ((MIN((int)firstArray.count, (int)secondArray.count)-1));
        
        while(iterations > 0){
            
            int j = i;
            while(count <= (MIN(firstArray.count, secondArray.count) - 1)){
                
                if(firstArray.count > secondArray.count){
                    
                    [smallerArray addObject:[firstArray objectAtIndex:j]];
                }else{
                    
                    [smallerArray addObject:[secondArray objectAtIndex:j]];
                }
                j++;
                count++;
            }
            
            if([smallerArray isEqualToArray:firstArray]){
                
                return @"sublist";
            
            }else if([smallerArray isEqualToArray:secondArray]){
                
                return @"superlist";
            }else{
                
                [smallerArray removeAllObjects];
                i++;
                count=0;
            }
            
            
            iterations--;
        }
        
    }
    
        return @"unequal";
}
@end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
trackler-2.0.6.38 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.37 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.36 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.35 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.34 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.33 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.32 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.31 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.30 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.29 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.28 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.27 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.26 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.25 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.24 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.23 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.22 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.21 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.6.20 tracks/objective-c/exercises/sublist/SublistExample.m