Ruby: No of times an element is repeated in an array : I know there are a lot more methods to solve this but I'm just curious to solve it using this way. Here is my code:

        a = [5,2,4,1,2]
        b=[]
        for i in a
             unless b.include?a[i]
               b << a[i]
               print i," appears ",a.count(i)," times\n"
             end
        end
        print b
**NOTE: I added `print b` just to know find where I'm going wrong**.Here is the output I'm getting:
`
 5 appears 1 times
 2 appears 2 times
 4 appears 1 times
 [nil, 4, 2]`