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.119 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.118 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.117 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.116 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.115 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.114 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.113 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.111 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.110 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.109 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.108 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.107 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.106 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.105 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.104 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.103 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.102 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.101 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.100 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m
trackler-2.2.1.99 tracks/objective-c/exercises/flatten-array/FlattenArrayExample.m