- Create an object (module) that enables creation of the following:
that has the following:
- properties:
name- provided through a constructor function or init method
- methods:
addPlaylist(playlistToAdd)- Adds a playlist to the player
playlistToAddmust be aPlayListinstance- Otherwise, throw an error
- Enables chaining
getPlaylistById(id)- Finds and returns a playlist from the playlists in this player instance
- Returns null, if a playlist with the provided id is not contained in the player
removePlaylist(id)- Removes a playlists from this player instance, and the playlist must have an
idequal to the providedid - Enables chaining
- Throws an error, if a playlist with the provided
idis not contained in the player
- Removes a playlists from this player instance, and the playlist must have an
removePlaylist(playlist)- Removes a playlists from this player instance, and the playlist must have an
idequal to theidof the provided playlist - Enables chaining
- Throws an error, if a playlist with the provided id is not contained in the player
- Removes a playlists from this player instance, and the playlist must have an
listPlaylists(page, size)- Returns an array with at most size
sizeand containing the playlists with indices pagesize, pagesize+1, page*size+2, ... (page+1)*size-1- These are the indices after sorting the playlist by name, then by id
- If there are less that
sizeplaylists, return all of them - Throw an error if:
- page*size > COUNT_OF_PLAYLISTS_IN_PLAYER
- page < 0
- size <= 0
- Returns an array with at most size
contains(playable, playlist)-
Checks whether a playlist contains a playable
-
Returns true or false
-
Example:
//having 35 playlists: //listPlaylists(2, 10) should return playlists with indices from 20 to 29, including //listPlaylists(3, 10) should return playlists with indices from 30 to 34, including
-
search(pattern)-
Returns an array of all playlists, that contain a song, which title contains the
pattern- In the returned array, only id and title of the playlists are returned
-
Returns empty array ig no such playlists exists
-
Example:
//having player with name `Batman's playlist` with: //playlist1 with id `1` and title `Cool` with playables: // 'They are green' and 'I am Batman' //playlist2 with id `2` and title `Green` with playables: // `Green they are`, `Green is beautiful` and `To the green and beyond` //player.search('green') returns: // [{name: 'Cool', id: 1}, {name: 'Green', id: 2}] //player.search('batman') returns: // [{name: 'Cool', id: 1}] //player.search('John') returns: // []
-
that has the following:
- properties:
id- generated when the playlist is createdname- provided through a constructor function or init method
- methods:
addPlayable(playable)- Adds a playable to the
PlayList - The same playable can be added multiple times
- Enables chaining
- Adds a playable to the
getPlayableById(id)- Returns the playable that has the provided
id - Returns null, if no playable is found with the provided
id
- Returns the playable that has the provided
removePlayable(id)- Removes a playable from this playlist, and the playable must have an
idequal to the providedid - Enables chaining
- Throws an error, if a playable with the provided
idis not contained in the playlist
- Removes a playable from this playlist, and the playable must have an
removePlayable(playable)- Removes a playable from this playlist, and the playable must have an
idequal to theidof the provided playable - Enables chaining
- Throws an error, if a playable with the provided id is not contained in the playlist
- Removes a playable from this playlist, and the playable must have an
listPlayables(page, size)-
Returns an array with at most size
sizeand containing the playables with indicespage*size, page*size+1, page*size+2, ... (page+1)*size-1- These are the indices after sorting the playables by
title, then byid
- These are the indices after sorting the playables by
-
If there are less that
sizeplayables, return all of them -
Throw an error if:
page*size > COUNT_OF_PLAYABLE_IN_PLAYLISTpage < 0size <= 0
-
Example:
//having 35 playables: //rockPlaylist.listPlayables(2, 10) should return playables with indices from 20 to 29, including //rockPlaylist.listPlayables(3, 10) should return playables with indices from 30 to 34, including
-
that has the following :
- properties:
id- generated when the playable is createdtitle- provided through a constructor function or init methodauthor- provided through a constructor function or init method
- methods:
play()- returns a string in the format:
[id]. [title] - [author]
- returns a string in the format:
that inherits Playable and adds the following:
- properties:
length- provided through a constructor function or init method
- number, greater than 0
- methods:
play()- reuses the
play()fromPlayableand adds:- [length]at the end
- reuses the
that inherits Playable and adds the following:
- properties:
imdbRating- provided through a constructor function or init method
- number, between 1 and 5
- methods:
play()- reuses the
play()fromPlayableand adds:- [imdbRating]at the end
- reuses the
-
All
idare numbers, greater than 0 -
Each player instance has an unique
id -
Each playlist instance has an unique
id -
Each playable instance has an unique
id -
Properties
name,titleandauthorare a strings between 3 and 25 characters -
You can use any Inheritance in JavaScript you like
- For example: Prototypal or Classical
var module = {
getPlayer: function (name){
// returns a new player instance with the provided name
},
getPlaylist: function(name){
//returns a new playlist instance with the provided name
},
getAudio: function(title, author, length){
//returns a new audio instance with the provided title, author and length
},
getVideo: function(title, author, imdbRating){
//returns a new video instance with the provided title, author and imdbRating
}
};