Sha256: ec56f56db5cc3144e52efeb1d879c1e91e0a56fe2d048a3bbb49afe2812f3d10

Contents?: true

Size: 1.64 KB

Versions: 262

Compression:

Stored size: 1.64 KB

Contents

#import "SublistExample.h"

@implementation SublistExample

+ (SublistKind)classifierForFirstList:(NSArray *)firstArray andSecondList:(NSArray *)secondArray { //!OCLint
    
    if ([firstArray isEqualToArray:secondArray]){
        return SublistKindEqual;
    } else if (firstArray.count == 0 || secondArray.count == 0) {
        if (firstArray.count == 0) {
            return SublistKindSublist;
        }
        
        return SublistKindSuperlist;
    } else if (firstArray.count != secondArray.count) {
        int i = 0; //!OCLint
        int count = 0;
        NSMutableArray *smallerArray = [NSMutableArray array];
        
        unsigned long iterations = 0;
        iterations = MAX(firstArray.count, secondArray.count) - ((MIN(firstArray.count, secondArray.count) - 1));
        
        while (iterations > 0) {
            int j = i; //!OCLint
            
            while (count <= (MIN(firstArray.count, secondArray.count) - 1)) {
                if (firstArray.count > secondArray.count) {
                    [smallerArray addObject:firstArray[j]];
                } else {
                    [smallerArray addObject:secondArray[j]];
                }
                
                j++;
                count++;
            }
            
            if ([smallerArray isEqualToArray:firstArray]) {
                return SublistKindSublist;
            } else if ([smallerArray isEqualToArray:secondArray]) {
                return SublistKindSuperlist;
            }
            
            [smallerArray removeAllObjects];
            i++;
            count = 0;
            iterations--;
        }
    }
    
    return SublistKindUnequal;
}
@end

Version data entries

262 entries across 262 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/sublist/SublistExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/sublist/SublistExample.m