Skip to content

Commit

Permalink
Fix bug in Array#rindex that broke 2 rubyspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 20, 2013
1 parent e80a425 commit 5ec2bdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 10 additions & 7 deletions corelib/array.rb
Expand Up @@ -853,7 +853,14 @@ def reverse_each(&block)

def rindex(object = undefined, &block)
%x{
if (block !== nil) {
if (object != null) {
for (var i = #{self}.length - 1; i >= 0; i--) {
if (#{`#{self}[i]` == `object`}) {
return i;
}
}
}
else if (block !== nil) {
for (var i = #{self}.length - 1, value; i >= 0; i--) {
if ((value = block(#{self}[i])) === $breaker) {
return $breaker.$v;
Expand All @@ -864,12 +871,8 @@ def rindex(object = undefined, &block)
}
}
}
else {
for (var i = #{self}.length - 1; i >= 0; i--) {
if (#{`#{self}[i]` == `object`}) {
return i;
}
}
else if (object == null) {
return #{enum_for :rindex};
}
return nil;
Expand Down
2 changes: 0 additions & 2 deletions spec/filters/bugs/array/rindex.rb
@@ -1,6 +1,4 @@
opal_filter "Array#rindex" do
fails "Array#rindex given no argument and no block produces an Enumerator"
fails "Array#rindex rechecks the array size during iteration"
fails "Array#rindex ignore the block if there is an argument"
fails "Array#rindex returns the first index backwards from the end where element == to object"
end

0 comments on commit 5ec2bdf

Please sign in to comment.