Build a Playlist Remix Engine - Build a Playlist Remix Engine

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

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-playlist-remix-engine/6976db7ecfa770bf21307b20.md at main · freeCodeCamp/freeCodeCamp · GitHub

The Array.isArray() method is first mentioned in loops in the explanation of for in loops https://www.freecodecamp.org/learn/javascript-v9/lecture-working-with-loops/what-is-the-for-in-loop-and-when-should-you-use-it. This does come before this challenge.

That said you were clearly not able to recall this, and the notes are not always easy to find again. Would you be able to log an issue on Github?

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.