Skip to content

Instantly share code, notes, and snippets.

@sandboxws
Created September 28, 2011 20:18
Show Gist options
  • Select an option

  • Save sandboxws/1249140 to your computer and use it in GitHub Desktop.

Select an option

Save sandboxws/1249140 to your computer and use it in GitHub Desktop.
JavaScript function snippet
var getAlbumName = function(trackName) {
var albumName = null;
var albums = {
theDarkSideOfTheMoon: {
title: 'The Dark Side of the Moon',
tracks: [
{title: 'Speak To Me'},
{title: 'Breathe'},
{title: 'On The Run'},
{title: 'Time'},
{title: 'The Great Gig In The Sky'},
{title: 'Money'},
{title: 'Us And Them'},
{title: 'Any Colour You Like'},
{title: 'Brain Damage'},
{title: 'Eclipse'}
]
}
};
for(_album in albums) {
album = albums[_album];
tracks = album['tracks'];
for(idx in tracks) {
track = tracks[idx];
if(track['title'] == trackName) {
albumName = album['title'];
return albumName;
}
}
}
};
getAlbumName('Breathe');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment