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.8.34 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.33 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.32 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.31 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.30 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.29 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.28 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.27 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.26 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.24 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.23 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.22 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.21 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.20 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.19 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.18 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.17 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.16 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.15 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.0.8.14 tracks/objective-c/exercises/sublist/SublistExample.m