Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
oldschoolshuffle
function convertPlaylistToObjectByProperty(simplifiedPlaylist, propertyName){
//use to group large array of tracks into smaller arrays of tracks from same album
//this lets us easily sort tracks for a single album, then do a for..in loop
//over each albumId as an object key and combine the arrays back together
let playlistObject = {};
//eslint-disable-next-line
simplifiedPlaylist.map((track) => {
if (!playlistObject[track[propertyName]]) {
playlistObject[track[propertyName]] = [];
}
playlistObject[track[propertyName]].push(track)
})
//now sort the array in each property by trackNumber, so tracks play in the same order as the album
for (let relatedTrackArray in playlistObject) {
playlistObject[relatedTrackArray].sort(dynamicSort('trackNumber'));
}
return playlistObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.