Created
October 5, 2012 20:58
-
-
Save scottchiang/3842362 to your computer and use it in GitHub Desktop.
convert nested array to hash
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
| def convert_to_hash | |
| data_table = [] | |
| #data_table[0] = ["Number", "Name", "Position", "Points per Game"] | |
| data_table[0] = ["12", "Joe Schmo", "Center", "[14, 32, 7, 0, 23]"] | |
| data_table[1] = ["9", "Ms. Buckets", "Point Guard", "[19, 0, 11, 22, 0]"] | |
| data_table[2] = ["31", "Harvey Kay", "Shooting Guard", "[0, 30, 16, 0, 25]"] | |
| data_table[3] = ["18", "Sally Talls", "Power Forward", "[18, 29, 26, 31, 19]"] | |
| data_table[4] = ["22", "MK BiBoux", "Small Forward", "[11, 0, 23, 17, 0]"] | |
| hash_data_table = [] | |
| i = 0 | |
| table_title = ["Number", "Name", "Position", "Points per Game"] | |
| while i < data_table.length | |
| hash_data_table[i] = Hash[table_title.zip(data_table[i])] | |
| i += 1 | |
| end | |
| hash_data_table | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment