Skip to main content

Playlist Soundness

A Learning TypeScript > Interfaces 🍲 entree project.

What's up, friend?! I'm so pumped you're joining us. We've got a sick project we could totally use your help on!

See, someone's giving us amazing recommendations for songs to play. But they're not just coming in as songs. Sometimes they're an album containing a array of songs. And sometimes they're a playlist with a method that returns an array of songs.

We'd like you to write a function for us that takes in an array of those items and returns a result playlist. The result playlist should keep track of which songs appear under each artist, the in-order list of songs, and the total length of time across the playlist?

Can you do this for us, please? Friend?

Setup

If you haven't yet, set up the github.com/LearningTypeScript/projects repository locally.

git clone https://github.com/LearningTypeScript/projects learning-typescript-projects
cd learning-typescript-projects
npm i

Change your terminal directory to this project's:

cd projects/interfaces/playlist-soundness

In one terminal, start the TypeScript compiler in watch mode:

tsc --watch

In another terminal, run Jest via the test script. For example, to run tests in watch mode:

npm test -- --watch

Specification

Your code should export an unrollPlaylist function with an explicit return type annotation.

Parameters:

  1. items: An array where each element is either a Song, Album, or Playlist

    See ./index.test.ts for examples of data.

Return type: an object with..

  • artists: Object with artist names keyed to the array of songs they're credited on
  • songs: An array of Songs
  • time: Total length of time across all songs

Notes

  • Don't import code from one step into another.