-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathozans-playlist.js
More file actions
62 lines (57 loc) · 1.4 KB
/
Copy pathozans-playlist.js
File metadata and controls
62 lines (57 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// @ts-check
//
// The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion when
// implementing this exercise.
/**
* Removes duplicate tracks from a playlist.
*
* @param {string[]} playlist
* @returns {string[]} new playlist with unique entries
*/
export function removeDuplicates(playlist) {
return [...new Set(playlist)];
}
/**
* Checks whether a playlist includes a track.
*
* @param {string[]} playlist
* @param {string} track
* @returns {boolean} whether the track is in the playlist
*/
export function hasTrack(playlist, track) {
return playlist.includes(track);
}
/**
* Adds a track to a playlist.
*
* @param {string[]} playlist
* @param {string} track
* @returns {string[]} new playlist
*/
export function addTrack(playlist, track) {
playlist.push(track);
return removeDuplicates(playlist);
}
/**
* Deletes a track from a playlist.
*
* @param {string[]} playlist
* @param {string} track
* @returns {string[]} new playlist
*/
export function deleteTrack(playlist, track) {
return playlist.filter(song => song != track);
}
/**
* Lists the unique artists in a playlist.
*
* @param {string[]} playlist
* @returns {string[]} list of artists
*/
export function listArtists(playlist) {
const artists = playlist.map(track => {
return track.split("-")[1].trim();
});
return removeDuplicates(artists);
}