in reply to Summing Up Array Elements By Group
Or a bit more idiomatic:my @arr = (0,0,1, 3,2,0, 1,1,1); my @output; for @arr -> $a, $b, $c { @output.push: $a + $b + $c; } say @output.perl; # output: [1, 5, 3]
my @arr = (0,0,1, 3,2,0, 1,1,1); my @output = gather { for @arr -> $a, $b, $c { take $a + $b + $c; } }
(This one would even be lazy if Rakudo did laziness yet).
|
|---|