Skip to content

Instantly share code, notes, and snippets.

@gate5th gate5th/NA
Created Sep 12, 2018

Embed
What would you like to do?
oldschoolshuffle
//Start out with a playlist with songs from multiple albums in no particular order
[{albumId: A, trackname: "Dream Maker", trackNumber: 3},
{albumId: C, trackname: "Mess", trackNumber: 1},
{albumId: B, trackname: "Dont", trackNumber: 9},
{albumId: W, trackname: "Me", trackNumber: 5},
{albumId: A, trackname: "Heartbreaker", trackNumber: 2},
{albumId: W, trackname: "With", trackNumber: 2},
{albumId: C, trackname: "Around", trackNumber: 6},
{albumId: A, trackname: "Love Taker", trackNumber: 6}]
//organize the array into object properties based on albumId
{
A: [{albumId: A, trackname: "Dream Maker", trackNumber: 3},
{albumId: A, trackname: "Heartbreaker", trackNumber: 2},
{albumId: A, trackname: "Love Taker", trackNumber: 6}
],
B: [{albumId: B, trackname: "Dont", trackNumber: 9}],
C: [{albumId: C, trackname: "Mess", trackNumber: 1},
{albumId: C, trackname: "Around", trackNumber: 6}
],
W: [{albumId: W, trackname: "Me", trackNumber: 5}
{albumId: W, trackname: "With", trackNumber: 2},
]
}
//and finally sort each album array by track number
{
A: [{albumId: A, trackname: "Heartbreaker", trackNumber: 2},
{albumId: A, trackname: "Dream Maker", trackNumber: 3},
{albumId: A, trackname: "Love Taker", trackNumber: 6}
],
B: [{albumId: B, trackname: "Dont", trackNumber: 9}],
C: [{albumId: C, trackname: "Mess", trackNumber: 1},
{albumId: C, trackname: "Around", trackNumber: 6}
],
W: [{albumId: W, trackname: "With", trackNumber: 2},
{albumId: W, trackname: "Me", trackNumber: 5}
]
}
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.