10.9.1 The Graund well rubist 3
a = [1,2,3,4,5]
e = Enumerator.new do |y|
total = 0
until a.empty?
total += a.pop
y << total
end
end
e.take(2)
=> [5, 9]
a
=> [1, 2, 3]
e.to_a
=> [3, 5, 6]
a
=> []
Code language: Ruby (ruby)
10.9.1 The Graund well rubist 3
a = [1,2,3,4,5]
e = Enumerator.new do |y|
total = 0
until a.empty?
total += a.pop
y << total
end
end
e.take(2)
=> [5, 9]
a
=> [1, 2, 3]
e.to_a
=> [3, 5, 6]
a
=> []
Code language: Ruby (ruby)