Empty arrays are not in the challenge. That said, it was an interesting challenge to address.
The reason some are removed is the flattening logic removes and second level and beyond empty arrays.
To remove the first level empty arrays, add a filter to the return value:
.filter { !(($0 as? Array<Any>)?.isEmpty ?? false) }
Well, usually I make same "if x then return" oneliners. Guard needed to avoid nested if's Here we can choose whatever we like.
Why .compactMap{ $0.wholeNumberValue}?
.compactMap{ $0.wholeNumberValue}
Your if statement is acting as a guard clause. Would read better if you used guard since those are expected to bail.
if ... return is really acting as a guard clause. it would be better to use a guard.
Loading collection data...
Empty arrays are not in the challenge. That said, it was an interesting challenge to address.
The reason some are removed is the flattening logic removes and second level and beyond empty arrays.
To remove the first level empty arrays, add a filter to the return value:
.filter { !(($0 as? Array<Any>)?.isEmpty ?? false) }
Well, usually I make same "if x then return" oneliners.
Guard needed to avoid nested if's
Here we can choose whatever we like.
Why
.compactMap{ $0.wholeNumberValue}
?Your if statement is acting as a guard clause. Would read better if you used guard since those are expected to bail.
if ... return is really acting as a guard clause. it would be better to use a guard.