Created
April 29, 2011 20:25
-
-
Save epatel/948970 to your computer and use it in GitHub Desktop.
flattenArray(array) -- flattens a hierarchy of NSArrays (should be a category I guess) [reason https://twitter.com/ikenndac/status/63609670182502400 -- but not a oneliner]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *flattenArray(NSArray *arr) { | |
NSMutableArray *collector = [NSMutableArray array]; | |
for (id obj in arr) { | |
if ([obj isKindOfClass:[NSArray class]]) | |
[collector addObjectsFromArray:flattenArray(obj)]; | |
else | |
[collector addObject:obj]; | |
} | |
return collector; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment