lundi 18 mai 2020

Syntax error, unexpected ',', expecting keyword_end arr.each_with_index |ele1, idx1|

Get the following error when testing this method.

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

Goal is to take in an array of unique numbers and return the number of pairs of elements that sum to 0.

The other errors that show up are:

syntax error, unexpected ',', expecting keyword_end
        arr.each_with_index |ele2, idx2|

and

 syntax error, unexpected keyword_end, expecting end-of-input

Aucun commentaire:

Enregistrer un commentaire