Last active
February 17, 2020 14:54
-
-
Save goodviber/96e4017cd51390e9e99f8b68a2f04271 to your computer and use it in GitHub Desktop.
Hash values as arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @avg_score_hash = Hash.new { |hash, key| hash[key] = [] } | |
| @rows.each do |row| | |
| row.last.each_with_index do |column, index| | |
| if column != 0 | |
| @avg_score_hash[index] << column | |
| end | |
| end | |
| end | |
| @avg_score_hash | |
| #=> {2=>[92.73], 5=>[90.91, 95.56, 90.91], 3=>[93.33], 0=>[100.0]} | |
| @avg_score_hash.map { |k,v| [k, [v.sum/v.size]]}.to_h | |
| #=> {2=>[92.73], 5=>[92.46], 3=>[93.33], 0=>[100.0]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment