2 ms·
You can make it nicer and more reliable with Perl: sub flatten { map { ref $_ eq 'ARRAY' ? flatten(@$_) : $_ } @_ } However, this is not somet
by zzzcpan 10y ago
You can make it nicer and more reliable with Perl:
sub flatten {
map { ref $_ eq 'ARRAY' ? flatten(@$_) : $_ } @_
}
However, this is not something a Java/OO programmer would be comfortable with, especially under the stress of the interview. As it's a bit higher level and closer to a functional way of thinking, than OO.
- cestith 10y agoI started to use map, but I've been told time and again anything that does is not a trivial example because you start by explaining what map does. Anyway, I'm glad the first response to "this is trivial in Perl" is another, simpler Perl response rather than "Perl is dead".