Tell us what’s happening:
Just want to point out that the Array.isArray method does not appear to be discussed in any of the previous Theory sections. I haven’t searched through the workshops, but I don’t recall seeing anything there about testing if an object is an array.
Students (like me) may struggle to get started with this lab as currently written. I found out about this method by looking up other posts on the forum which used the method, not from the curriculum.
Your code so far
const playlists = [
[
{
trackId: "trk101",
artist: "Velvet Comet",
title: "Crimson Afterglow",
votes: 5,
bpm: 122
},
{
trackId: "trk102",
artist: "Neon Harbor",
title: "Static Horizon",
votes: 2,
bpm: 108
},
{
trackId: "trk103",
artist: "Lunar Arcade",
title: "Midnight Frequency",
votes: 4,
bpm: 128
}
],
[
{
trackId: "trk201",
artist: "Solar Echo",
title: "Glass Skyline",
votes: 3,
bpm: 115
},
{
trackId: "trk202",
artist: "Velvet Comet",
title: "Satellite Hearts",
votes: 6,
bpm: 124
}
]
];
// 1.
function flattenPlaylists(playlists) {
// trackId, artist, title, votes, bpm
const flattenedPlaylist = [];
if ((typeof playlists) !== "Array") {
return flattenedPlaylist;
}
for (let playlistIndex = 0; playlistIndex < playlists.length; playlistIndex++){
console.log(playlists[playlistIndex])
for (let trackIndex = 0; trackIndex < playlists[playlistIndex].length; trackIndex++) {
//{source: [playlistIndex, trackIndex]}
flattenedPlaylist.push({
source: [playlistIndex, trackIndex],
...playlists[playlistIndex]
})
}
}
return flattenedPlaylist;
}
console.log(Array.isArray(playlists)); // true
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0
Challenge Information:
Build a Playlist Remix Engine - Build a Playlist Remix Engine