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.

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

Open your editor in this project's directory:

shell
code projects/interfaces/playlist-soundness
shell
code projects/interfaces/playlist-soundness

In one terminal, run the TypeScript compiler via the tsc script. For example, to start the TypeScript compiler in watch mode:

shell
npm run tsc -- --watch
shell
npm run tsc -- --watch

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

shell
npm run test -- --watch
shell
npm run 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

Note: your terminal should be in the playlist-soundness directory, not the root repository's directory.

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