Build a Playlist Remix Engine - Build a Playlist Remix Engine

Tell us what’s happening:

  1. When duplicate trackId values exist, dedupeTracks should keep only the first occurrence of the track.

tried all but no luck

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
    }
  ]
];
function flattenPlaylists(playlists) {
  if(!Array.isArray(playlists))
  {
    return [];
  }
  return playlists.flatMap((playlist, playlistIndex) =>
    playlist.map((track, trackIndex) => (
      {
      ...track,
      source: [playlistIndex, trackIndex]
    }
    ))
  );
}
//console.log(flattenPlaylists(playlists));
let array=flattenPlaylists(playlists);
console.log(array);

function scoreTracks(array)
{
return array.map((track)=>({
          
           ...track, 
          score:(track.votes * 10) - Math.abs(track.bpm - 120) }));


} 
let dupeTrack=scoreTracks(array);
console.log(dupeTrack);
//const seenTrackIds = new Set();


function dedupeTracks(dupeTrack)
{
  let result=[];
    const seen = new Set();
  return dupeTrack.filter(track=>{
  if (!seen.has(track.trackId)) {
            seen.add(track.trackId);
            result.push(track);
        }
    return result; 
})
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0

Challenge Information:

Build a Playlist Remix Engine - Build a Playlist Remix Engine

Your question as it stands is very low effort. You have not given enough information about what you tried or what your results were or how we can help you.

I suggest that you take a read through this article on how to write strong questions:
https://medium.com/@gordon_zhu/how-to-be-great-at-asking-questions-e37be04d0603

Ok I am unable to get theough to this step:

When duplicate trackId values exist, dedupeTracks should keep only the first occurrence of the track.

I tried filter method too and tried to search of any other option but still stuck so please advise what should be done here.

why do you say you are unable?

for eg. do you think your function is working as they want it to work? have you tried to debug it somehow by using a debugger or adding console.logs and testing it? what were the results and conclusions you reached?

if you tested it and know it doesn’t work, you should try to describe your algorithm step-by-step to us. Then we can check to see if you have misunderstood something.

edit - i suggest looking up how filter works. it doesn’t look like you understand it. if you test your code with more console.logs inside the filter, you’ll see what i mean