All Tracks/lab playlist remix engine/
Đang tải...
Hướng dẫn thử thách
1 / 1

Build a Playlist Remix Engine

In this lab, you will build a program that creates a single remix playlist from multiple playlists submitted by listeners. Each listener provides a list of songs they want to hear. Some songs may appear more than once, and some artists may show up too many times. Your job is to work through these playlists step by step: combine them into one list, score each song, remove duplicate songs, limit how often the same artist appears, and then create a final play order. **Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. **User Stories:** 1. You should create a function named `flattenPlaylists` that accepts an array of playlists where each playlist is an array of objects with the following properties: `trackId`, `artist`, `title`, `votes`, `bpm`. If the input is not an array, `flattenPlaylists` should return an empty array. An example playlist has been provided for you. You can use this example to test out your function. 2. `flattenPlaylists` should return a flat array of track objects, where each object includes all the original track properties plus a `source` property set to an array with the playlist index and the track index indicating where the track originated. 3. You should create a function named `scoreTracks` that accepts an array of track objects as returned by `flattenPlaylists` (each with `trackId`, `artist`, `title`, `votes`, `bpm`, and `source` properties) and returns a new array of track objects, each with a `score` property added using the formula: `votes * 10 - Math.abs(bpm - 120)`. 4. You should create a function named `dedupeTracks` that accepts an array of track objects as returned by `scoreTracks` and returns a new array with duplicate `trackId` entries removed, keeping only the first occurrence of each. 5. You should create a function named `enforceArtistQuota` that accepts an array of track objects as returned by `dedupeTracks` and a number representing the maximum allowed occurrences per artist. The function should return a new array where no artist appears more times than the given number, keeping the earliest occurrences. 6. You should create a function named `buildSchedule` that accepts an array of track objects as returned by `enforceArtistQuota` and returns a new array of `{ slot, trackId }` objects, where `slot` is a 1-based index representing each track's position in the broadcast order. 7. You should create a function named `remixPlaylist` that accepts an array of playlists and the maximum number of allowed occurrences per artist. The function should return the final broadcast schedule as an array of `{ slot, trackId }` objects, by calling `flattenPlaylists`, `scoreTracks`, `dedupeTracks`, `enforceArtistQuota`, and `buildSchedule` in order.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.js
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.