Project: Music Playlist Manager

Story Welcome to MusicBee, a cutting-edge music streaming service. You are part of the development team, and your task is to build a sophisticated Music Playlist Manager. This manager will allow users to manage their playlists with various functionalities like adding songs, removing songs, searching songs, sorting playlists, filtering songs by genre, and generating statistics.

Objectives

By the end of this exercise, students will be able to:

  1. Create, manipulate, and transform arrays of objects.
  2. Use higher-order functions such as map, filter, reduce, find, and sort.
  3. Apply concepts of immutability and pure functions.
  4. Implement practical solutions for complex problems using JavaScript arrays and collections.

Task Breakdown

Task 1: Initialize the Playlist

Create an array of song objects. Each song should have the following properties: id, title, artist, album, genre, duration (in seconds), and playCount.

Task 2: Add a New Song

Implement a function addSong that adds a new song to the playlist. Ensure the function does not mutate the original array.

Task 3: Remove a Song

Implement a function removeSong that removes a song from the playlist based on its id. Ensure the function does not mutate the original array.

Task 4: Search Songs by Title

Create a function searchSongsByTitle that searches for songs by their title.

Task 5: Sort Playlist by Duration

Implement a function sortPlaylistByDuration that sorts the playlist by song duration in ascending order.

Task 6: Filter Songs by Genre

Write a function filterSongsByGenre that filters songs by a specific genre.

Task 7: Generate Playlist Statistics

Create a function generateStatistics that returns an object with the following statistics:

  • Total number of songs
  • Total duration of the playlist (in minutes)
  • Average play count

Additional Challenge: Advanced Search Functionality

Implement a function advancedSearch that allows users to search for songs based on multiple criteria (title, artist, genre) and return matching songs.