Ruby 语法错误,意外'';,应为关键字_end arr.each_,索引为| ele1,idx1|
测试此方法时出现以下错误Ruby 语法错误,意外'';,应为关键字_end arr.each_,索引为| ele1,idx1|,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,测试此方法时出现以下错误 def opposite_count(nums) pairs = [] arr.each_with_index |ele1, idx1| arr.each_with_index |ele2, idx2| if (idx2 > idx1) && (ele1 + ele2 == 0) pairs << ele1 end end
def opposite_count(nums)
pairs = []
arr.each_with_index |ele1, idx1|
arr.each_with_index |ele2, idx2|
if (idx2 > idx1) && (ele1 + ele2 == 0)
pairs << ele1
end
end
end
return pairs.length
end
及
两个循环的
每个带有索引的\u之后都缺少do
关键字
此外,如果未定义arr
,这将给您带来进一步的错误
syntax error, unexpected ',', expecting keyword_end
arr.each_with_index |ele2, idx2|
syntax error, unexpected keyword_end, expecting end-of-input