Last Updated: February 25, 2016
·
386
· navateja

Ruby - Find if all the elements in the array are same

<array>.uniq.length == 1
# Example

a = [1,1,1]
a.uniq.length == 1
=> true

a = [1,1,2]
a.uniq.length == 1
=> false