Skip to content

Instantly share code, notes, and snippets.

@gate5th
Created September 12, 2018 18:57
Show Gist options
  • Save gate5th/872bf4bb95ca84a2cdced93ada86172c to your computer and use it in GitHub Desktop.
Save gate5th/872bf4bb95ca84a2cdced93ada86172c to your computer and use it in GitHub Desktop.
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