3083663a71
started translation-service
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
// @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) {
|
|
let list = [...new Set(playlist)];
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
let list = new Set(playlist);
|
|
return list.has(track);
|
|
}
|
|
|
|
/**
|
|
* Adds a track to a playlist.
|
|
*
|
|
* @param {string[]} playlist
|
|
* @param {string} track
|
|
* @returns {string[]} new playlist
|
|
*/
|
|
export function addTrack(playlist, track) {
|
|
let list = new Set(playlist);
|
|
list.add(track);
|
|
return Array.from(list);
|
|
}
|
|
|
|
/**
|
|
* Deletes a track from a playlist.
|
|
*
|
|
* @param {string[]} playlist
|
|
* @param {string} track
|
|
* @returns {string[]} new playlist
|
|
*/
|
|
export function deleteTrack(playlist, track) {
|
|
let list = new Set(playlist);
|
|
list.delete(track);
|
|
return Array.from(list)
|
|
}
|
|
|
|
/**
|
|
* Lists the unique artists in a playlist.
|
|
*
|
|
* @param {string[]} playlist
|
|
* @returns {string[]} list of artists
|
|
*/
|
|
export function listArtists(playlist) {
|
|
let list = new Set(playlist);
|
|
let artists = new Set;
|
|
var artist;
|
|
for (let song of list)
|
|
{
|
|
artist = song.split('- ');
|
|
artists.add(artist[1]);
|
|
}
|
|
|
|
return Array.from(artists);
|
|
}
|