I have the following line of code, anyone could decypher this syntax ?
@teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> a.points } [0..2]
I have the following line of code, anyone could decypher this syntax ?
@teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> a.points } [0..2]
I have the following line of code, anyone could decypher this syntax ?
@teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> a.points } [0..2]
take @teams, remove all teams where sport.id is not @sport.id, then sort them by points (descending) and return the top 3. Or in other words, return the top 3 teams for the sport designated by @sport
Fred
Yes, and I feel the duty to suggest that the equivalent
@teams.select {|a| a.sport.id == @sport.id }.sort { |a,b| b.points <=> a.points } [0…2]
Is (quite a bit?) clearer.