What I'm trying to get to is -
what is your desired output?
[nil, 4, 2]
does not look anything like "no of times an element is repeated in an array". What is
b
supposed to be? Also, it is probable that your error comes from misunderstanding what
i
is in
for i in a
, because you probably wouldn't write
a[i]
otherwise; but also
for ... in ...
is never ever used by Ruby programmers, and if you saw it in a book it's probably best to burn it. —
Amadan just now