Skip to content

Instantly share code, notes, and snippets.

@mecampbellsoup
Last active December 24, 2015 01:09
Show Gist options
  • Save mecampbellsoup/6721744 to your computer and use it in GitHub Desktop.
Save mecampbellsoup/6721744 to your computer and use it in GitHub Desktop.
Pass the method an artist name and a songs array and watch it werk.
require 'awesome_print' # awesome gem for making stuff look pretty
songs = [
"The Magnetic Fields - 69 Love Songs - Parades Go By",
"The Magnetic Fields - Get Lost - Smoke and Mirrors",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - New Shit",
"Neutral Milk Hotel - Boat Over Water - New Song!",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
"Neutral Milk Hotel - Boat Over Water - Another New Song",
"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 - The King of Carrot Flowers"]
def sort_songs_by_band_then_album(band_name, songs_array)
band_name_song_array = []
album_titles_array = []
songs_array.each do |song|
if song.split(" - ").first == band_name
band_name_song_array << song
end
end
band_name_song_array.each do |song|
album_titles_array << song.split(" - ")[1]
end
album_titles_array.uniq!
first_album = []
second_album = []
band_name_song_array.each do |song|
if song.split(" - ")[1] == album_titles_array.first
first_album << song
elsif song.split(" - ")[1] == album_titles_array[1]
second_album << song
end
end
ap (first_album + second_album)
end
sort_songs_by_band_then_album("The Magnetic Fields", songs)
sort_songs_by_band_then_album("Neutral Milk Hotel", songs)
#pin #day4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment