-
-
Save gate5th/872bf4bb95ca84a2cdced93ada86172c 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
//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