I am having problem sorting array into an ascending order, and then picking a value from the array to put into a new array.
# Splitting dance scores with "," and putting into arrays.
for dancers in results
a = dancers.split(",")
couplenumber = a[0]
score1 = a[1]
score2 = a[2]
score3 = a[3]
score4 = a[4]
score5 = a[5]
score6 = a[6]
score7 = a[7]
dancescores << Dancer.new(couplenumber, score1, score2, score3, score4, score5, score6, score7)
# Sorts the array into ascending order, and shows the 4 lowest values.
#p dancescores.sort.take(4)
# Getting the m value, from picking the 4th lowest number.
m = a[4]
newtest = [couplenumber, m]
coupleandscore << newtest
coupleandscore
end
puts coupleandscore
Right now it gives me the original values in the new array, which it should. But if i try to do
p dancescores.sort.take(4)
I will get this error:
[#<Dancer:0x10604a388 @score7=5, @score3=3, @score6=6, @score2=2, @score5=1, @score1=1, @couplenumber="34", @score4=3>]
examtest.rb:43:in `sort': undefined method `<=>' for #<Dancer:0x10604a388> (NoMethodError)
Any kind of help would be greatly appreciated!
<=>error is because you haven't defined a<=>method. See the documentation for theComparablemodule andEnumerable.sort.