Created
September 12, 2018 18:56
-
-
Save gate5th/5f3c9ab902fd2e105c7640da868a7344 to your computer and use it in GitHub Desktop.
oldschoolshuffle
This file contains 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
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