Sha256: bf930fc4eaf52b12c02ca8770189d484383469fca95b5d992a19657b32b22fc8

Contents?: true

Size: 889 Bytes

Versions: 268

Compression:

Stored size: 889 Bytes

Contents

#import "FlattenArrayExample.h"
static NSMutableArray *resultArray;
static NSNull *nullValue;

@implementation FlattenArrayExample

+ (NSArray *)flattenArray:(NSArray *)list{
    resultArray = [NSMutableArray array];
    nullValue = [NSNull null];
    
    for (int i = 0; i < list.count; i++) {
        if ([list[i] isKindOfClass:[NSArray class]]) {
            [FlattenArrayExample extractValuesFromArray:list[i]];
        } else if (list[i] != nullValue) {
            [resultArray addObject:list[i]];
        }
    }
    
    return resultArray;
}


+ (void)extractValuesFromArray:(NSArray*)array{
    for (int i = 0; i < array.count; i++) {
        if ([array[i] isKindOfClass:[NSArray class]]) {
            [FlattenArrayExample extractValuesFromArray:array[i]];
        } else if (array[i] != nullValue) {
            [resultArray addObject:array[i]];
        }
    }
    
}


@end

Version data entries

268 entries across 268 versions & 1 rubygems

Version Path
trackler-2.1.0.41 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.40 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.39 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.38 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.37 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.36 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.34 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.33 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.32 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.31 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.30 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.29 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.28 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.27 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.26 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.25 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.24 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.23 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.22 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.1.0.21 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m