Why does each traverse into the inner arrays as well (tried it with 3
and 4 deep?)
Array#length seems to be correct to me and Array#each_index
This seems to happen to collect!, and I'd gather other methods as well.
Convenient, if you want depth first traversal on all arrays. but what
if you just want to iterate in a shallow manner?
Why does each traverse into the inner arrays as well (tried it with 3
and 4 deep?)
Array#length seems to be correct to me and Array#each_index
This seems to happen to collect!, and I'd gather other methods as well.
Convenient, if you want depth first traversal on all arrays. but what
if you just want to iterate in a shallow manner?
> --- Ursprüngliche Nachricht ---
> Von: Ed Howland <ed.howland@gmail.com>
> An: ruby-talk@ruby-lang.org (ruby-talk ML)
> Betreff: Nuby Array questions - each iterates nested arrays?
> Datum: Thu, 27 Oct 2005 02:16:39 +0900
>
> a=[[1, 2, 3], [4, 5, 6]]
> => [[1, 2, 3], [4, 5, 6]]
> a.length
> => 2
> a.each {|x| puts x}
> 1
> 2
> 3
> 4
> 5
> 6
> => [[1, 2, 3], [4, 5, 6]]
> a.each_index {|x| puts x}
> 0
> 1
>
> Why does each traverse into the inner arrays as well (tried it with 3
> and 4 deep?)
> Array#length seems to be correct to me and Array#each_index
> This seems to happen to collect!, and I'd gather other methods as well.
>
> Convenient, if you want depth first traversal on all arrays. but what
> if you just want to iterate in a shallow manner?
>
> Thanks
> Ed
>