Skip to content
Browse files

Make take_last_while return elements in the original order.

  • Loading branch information...
1 parent 0c0be42 commit d4b2517bbd32a8fb4184743a0e8b86e38fe7a082 @mkwiatkowski mkwiatkowski committed Sep 4, 2013
View
2 lib/powerpack/enumerable/take_last_while.rb
@@ -12,7 +12,7 @@ def take_last_while
result = []
reverse_each do |elem|
return result unless yield(elem)
- result << elem
+ result.unshift(elem)
end
result
View
2 spec/powerpack/enumerable/take_last_while_spec.rb
@@ -2,6 +2,6 @@
describe 'Enumerable#take_last_while' do
it 'takes the last elements while a pred is true' do
- expect([1, 2, 3, 4, 6].take_last_while(&:even?)).to eq([6, 4])
+ expect([1, 2, 3, 4, 6].take_last_while(&:even?)).to eq([4, 6])
end
end

0 comments on commit d4b2517

Please sign in to comment.
Something went wrong with that request. Please try again.