Build a Playlist Remix Engine - Build a Playlist Remix Engine

Tell us what’s happening:

Attempting to complete test 10. Looks similar to test 8. Not able to properly translate loops to check/add artist to new array max number of times or less.

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(arr)
{
  let newArr = []
  if(!Array.isArray(arr))
  {return []}
  for(let a of arr)
  {
    for(let aR of a)
    {
      aR.source = [arr.indexOf(a),a.indexOf(aR)]
      console.log(aR)
      newArr.push(aR)
      
    }
  }
  return newArr
}
function scoreTracks(arr)
{
  let newArr = []
  if(!Array.isArray(arr))
  {return []}
  for(let a of arr)
  {
    a.score = a.votes * 10 - Math.abs(a.bpm - 120)
    newArr.push(a)
  }
  return newArr
}


function dedupeTracks(arr)
/*
create newArray to store items
loop through the argument array
if the newArr does not already have value of the current index of arr push the track
- check all elements of newarr to see of array

loop through arg array to see if current index of arg array matches any index of newArr 
-if at the end of loop and no matches continue to next 
 */
{
  let newArr = []
  for(let i = 0; i < arr.length; i++)
  {
    let count = 0
    //----------justincase
    if(i == 0)
    //-----------
    {
      newArr.push(arr[i])
    }
    for(let j = 0; j < newArr.length; j++)
    {
      //let count = 0
      if(newArr[j].trackId == arr[i].trackId){count++}
      if(count == 0 && j == newArr.length-1){newArr.push(arr[i])}
    }
  }
  return newArr
}

function enforceArtistQuota(arr,max)
/*

 */
{
  let newArr = []
  for(let i = 0; i < arr.length; i++)
  {
    let count = 0
    //----------justincase
    if(i == 0)
    //-----------
    {
      newArr.push(arr[i])
    }
    for(let j = 0; j < newArr.length; j++)
    {
      if(newArr[j].artist == arr[i].artist && count <= max)
      {
        count++
        newArr.push(arr[i])
        
      }
      
    }
  }
  return newArr
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.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

Hi @d3911ready,

Try testing your function to see what it returns:

console.log(enforceArtistQuota(dedupeTracks(scoreTracks(flattenPlaylists(playlists)))),1)

I suggest writing some logs inside the function to see what it’s doing. You may need to take another approach.

Happy coding