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.2.1.78 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.77 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.76 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.75 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.74 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.73 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.72 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.71 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.70 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.69 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.68 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.67 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.66 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.65 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.64 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.63 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.62 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.61 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.60 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.59 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m