Skip to content

Instantly share code, notes, and snippets.

@ashleygwilliams
Last active December 18, 2015 04:39
Show Gist options
  • Save ashleygwilliams/5726653 to your computer and use it in GitHub Desktop.
Save ashleygwilliams/5726653 to your computer and use it in GitHub Desktop.
i have [["a", "b", "c"],["a", "b", "z"],["d", "e", "f"],["d", "e", "p"]]
ok i need to buil {a=>??,d=>??}
THEN i need to build {a=>b, d=>e}
THEN i need to build {a=>{b=>??},d=>{e=>??}}
THEN i need to build {a=>{b=>[]]},d=>{e=>[]]}}
** maybe make [c,z] and [f,p]
THEN i need to build {a=>{b=>[c]]},d=>{e=>[f]]}}
THEN i need to build {a=>{b=>[c,z]]},d=>{e=>[f,p]]}}
i want {a=>{b=>[c,z]}, d=>{e=>[f,p]}}
i have {a=>{b=>[c,z,f,p]]},d=>{e=>[c,z,f,p]]}}
songs = [
"The Magnetic Fields - 69 Love Songs - Parades Go By",
"The Magnetic Fields - Get Lost - Smoke and Mirrors",
"The Magnetic Fields - Get Lost - You, Me, and the Moon",
"The Magnetic Fields - 69 Love Songs - The Book of Love",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - The King of Carrot Flowers"
]
song_chunks = []
songs.each do |song_info|
song_chunks.push(song_info.split(' - '))
end
#song_info = song[0] = "The Magnetic Fields - 69 Love Songs - Parades Go By"
#song_info.split('-') = ["The Magnetic Fields ", " 69 Love Songs ", " Parades Go By"]
albums = []
artists = []
songs_titles = []
playlist = {}
#playlist = {key:artist => {key:album=>[songs], key:album=>[songs]}}
song_chunks.each do |chunk|
playlist[chunk[0]] = {}
if x===y
x[artst]=song
elsif x=zip(enums
z[artist] = song
albums.push(chunk[1]) #in hash playlist find the key that equal the value of chunk[0]"artist" and set that key's value to an array wher ewe push album names(chunk[1])
songs_titles.push(chunk[2])
end
# {artist => {album => [songs]}}
puts playlist
puts songs
#{"neutral milk hotel => ["album1", "album2"]}
#ok so i am going to creat a new key with an artist name
#if the artist name is the same then add a key tot he hash that the key poitns to
#
students =
["Julian - Brooklyn - Bushwick",
"Alex - Long Island - Great Neck"]
#create a hash with this format:
#{"student_name => ["location=>more_specific_location"]"}
new_students = []
students.each do |student|
new_students.push(student.split(' - '))
end
location = []
# thisismyhash = {key=>{key2=>value}}
# thisismyhash[key] = {key2=>value}
# thisismyhash[key][key2] = value
# thisismyhash = {key=>{}}
# thisismyhash[key][key2] = value
# thisismyhash[key][key3] = value
#=> thisismyhash={key=>{key2=>value, key3=>value}}
student_hash = {}
new_students.each do |student|
student_hash[student[0]] = {student[1]=>student[2]}
end
puts student_hash
@julianchams
Copy link

yo so i've just been looking at this... and reading some articles on stackoverflow... and i still can't figure it out. i know it's supposed to be simple. alas, i can't do it.

songs = [
  "The Magnetic Fields - 69 Love Songs - Parades Go By",
  "The Magnetic Fields - Get Lost - Smoke and Mirrors",
  "The Magnetic Fields - Get Lost - You, Me, and the Moon",
  "The Magnetic Fields - 69 Love Songs - The Book of Love",
  "Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
  "Neutral Milk Hotel - In An Aeroplane Over the Sea - The King of Carrot Flowers"
]

    songChunks = []
    songs.each do |songinfo|
        songChunks.push(songinfo.split(' - '))
    end
    songtitles = []
    albums = []    
    library = {}

    songChunks.each do |chunk|
        library[chunk[0]] = {}
            if chunk[0] == library[chunk[0]] then   
 # i don't know what to equal it to... 
                library[chunk[0]] = songtitles.push(chunk[2]) 
# do arrays get deleted after they're used? i mean how to i get all different arrays for different groups of songs? are all songs gonna go to one array?
            elsif 
# am i supposed to write an elsif for each different album?
        end 
    end

    puts library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment