From 07a4924c9efe45ccd889753469d267694a36f9d7 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 10:03:25 +0300 Subject: [PATCH 01/26] playSong added play song func. --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 10f4784..6aff5b4 100644 --- a/index.js +++ b/index.js @@ -48,14 +48,20 @@ const player = { { id: 5, name: 'Israeli', songs: [4, 5] }, ], playSong(song) { - console.log(/* your code here */) - }, + console.log(`Playing ${song.title} from ${song.album} by ${song.artist} | ` + +((Math.floor(song.duration/60))<10? "0": "")+`${Math.floor(song.duration/60)}:${song.duration%60}.`) + } } - function playSong(id) { - // your code here + let notValId=true; + for(song of player.songs){ + if (song.id===id){ + player.playSong(song); + notValId=false; + } + } + if(notValId) throw "id not found"; } - function removeSong(id) { // your code here } From be700cc09a87d6a3f97e841453ac7ed46f812c6d Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 10:21:55 +0300 Subject: [PATCH 02/26] findSong added findSong func. --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6aff5b4..6ab9e6b 100644 --- a/index.js +++ b/index.js @@ -52,16 +52,20 @@ const player = { +((Math.floor(song.duration/60))<10? "0": "")+`${Math.floor(song.duration/60)}:${song.duration%60}.`) } } -function playSong(id) { +function findSong(id){ let notValId=true; for(song of player.songs){ if (song.id===id){ - player.playSong(song); - notValId=false; + return song; } } - if(notValId) throw "id not found"; + throw "id not found"; } + +function playSong(id) { + player.playSong(findSong(id)); +} + function removeSong(id) { // your code here } From 0ddfdce7ba8489f048cfecb23faa2129ec51f952 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 10:52:29 +0300 Subject: [PATCH 03/26] removeSong added removeSong func. --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6ab9e6b..20fe0f9 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +"use strict" const player = { songs: [ { @@ -54,7 +55,7 @@ const player = { } function findSong(id){ let notValId=true; - for(song of player.songs){ + for(let song of player.songs){ if (song.id===id){ return song; } @@ -63,11 +64,14 @@ function findSong(id){ } function playSong(id) { - player.playSong(findSong(id)); + player.playSong(findSong(id)); } function removeSong(id) { - // your code here + player.songs.splice(player.songs.indexOf(findSong(id)),1); + for(let playList of player.playlists){ + playList.songs.splice(playList.songs.indexOf(id),1) + } } function addSong(title, album, artist, duration, id) { From a41e677fd5f5bbbe1f2b32df8146df72bbdc554f Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:12:02 +0300 Subject: [PATCH 04/26] addSong added three func: generateId-for the default id parameter in addSong. durationTo Seconds-for the duration parameter in addSong. addSong. --- index.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 20fe0f9..909002f 100644 --- a/index.js +++ b/index.js @@ -73,9 +73,28 @@ function removeSong(id) { playList.songs.splice(playList.songs.indexOf(id),1) } } - -function addSong(title, album, artist, duration, id) { - // your code here +let newId=10; +function generateId(){ +newId+=1; +return newId; +} +function durationToSeconds(duration){ + return((parseInt(duration[0])*10)+parseInt(duration[1]))*60 + +parseInt(duration[3]*10)+parseInt(duration[4]) +} +function addSong(title, album, artist, duration, id=generateId()) { + try{ + findSong(id) + }catch(err) { + player.songs.push({"id":id, + "title": title, + "album": album, + "artist": artist, + "duration": durationToSeconds(duration), + }) + return id; + } + throw "ID taken" } function removePlaylist(id) { From 3747800c502fd118af201ea716e603e44c706a72 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:24:11 +0300 Subject: [PATCH 05/26] removePlaylist did it the same way as remove song also added findPlayList func. --- index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 909002f..bf71afe 100644 --- a/index.js +++ b/index.js @@ -53,14 +53,25 @@ const player = { +((Math.floor(song.duration/60))<10? "0": "")+`${Math.floor(song.duration/60)}:${song.duration%60}.`) } } -function findSong(id){ + +function findSong(id){ let notValId=true; for(let song of player.songs){ if (song.id===id){ return song; } } - throw "id not found"; + throw "ID not found"; +} + +function findPlayList(id){ + let notValId=true; + for(let playList of player.playlists){ + if (playList.id===id){ + return playList; + } + } + throw "ID not found"; } function playSong(id) { @@ -98,7 +109,7 @@ function addSong(title, album, artist, duration, id=generateId()) { } function removePlaylist(id) { - // your code here + player.playlists.splice(player.playlists.indexOf(findPlayList(id)),1); } function createPlaylist(name, id) { From 0c64d84b26b9e2d355a7517f11119fd330d98d0c Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:44:20 +0300 Subject: [PATCH 06/26] fixed L/l had small problem with big and small letters in 'playlist'('playList') --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index bf71afe..d1ff87d 100644 --- a/index.js +++ b/index.js @@ -64,11 +64,11 @@ function findSong(id){ throw "ID not found"; } -function findPlayList(id){ +function findPlaylist(id){ let notValId=true; - for(let playList of player.playlists){ - if (playList.id===id){ - return playList; + for(let Playlist of player.playlists){ + if (Playlist.id===id){ + return Playlist; } } throw "ID not found"; @@ -80,8 +80,8 @@ function playSong(id) { function removeSong(id) { player.songs.splice(player.songs.indexOf(findSong(id)),1); - for(let playList of player.playlists){ - playList.songs.splice(playList.songs.indexOf(id),1) + for(let playlist of player.playlists){ + playlist.songs.splice(playlist.songs.indexOf(id),1) } } let newId=10; @@ -109,7 +109,7 @@ function addSong(title, album, artist, duration, id=generateId()) { } function removePlaylist(id) { - player.playlists.splice(player.playlists.indexOf(findPlayList(id)),1); + player.playlists.splice(player.playlists.indexOf(findPlaylist(id)),1); } function createPlaylist(name, id) { @@ -120,11 +120,11 @@ function playPlaylist(id) { // your code here } -function editPlaylist(playlistId, songId) { +function editPlaylist(PlaylistId, songId) { // your code here } -function playlistDuration(id) { +function PlaylistDuration(id) { // your code here } From 51c8f0e4e962c466760b5bf636e2f8f7288c0528 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:46:56 +0300 Subject: [PATCH 07/26] generatePlaylistId added generatePlaylistId func. so also changed generateId to generateSongId --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d1ff87d..3711bf0 100644 --- a/index.js +++ b/index.js @@ -84,16 +84,16 @@ function removeSong(id) { playlist.songs.splice(playlist.songs.indexOf(id),1) } } -let newId=10; -function generateId(){ -newId+=1; -return newId; +let newSongId=10; +function generateSongId(){ +newSongId+=1; +return newSongId; } function durationToSeconds(duration){ return((parseInt(duration[0])*10)+parseInt(duration[1]))*60 +parseInt(duration[3]*10)+parseInt(duration[4]) } -function addSong(title, album, artist, duration, id=generateId()) { +function addSong(title, album, artist, duration, id=generateSongId()) { try{ findSong(id) }catch(err) { @@ -114,6 +114,11 @@ function removePlaylist(id) { function createPlaylist(name, id) { // your code here +let newPlaylistId=3 +function generatePlaylistId(){ + newPlaylistId+=1 + return newPlaylistId +} } function playPlaylist(id) { From 9c3be7d14f410661f1b789b362ffbde247f36d26 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:49:22 +0300 Subject: [PATCH 08/26] createPlaylist added createPlaylist func. simillar to addSong --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3711bf0..7f5b93c 100644 --- a/index.js +++ b/index.js @@ -112,13 +112,20 @@ function removePlaylist(id) { player.playlists.splice(player.playlists.indexOf(findPlaylist(id)),1); } -function createPlaylist(name, id) { - // your code here let newPlaylistId=3 function generatePlaylistId(){ newPlaylistId+=1 return newPlaylistId } + +function createPlaylist(name, id=generatePlaylistId()) { + try{ + findPlaylist(id) + }catch(err) { + player.playlists.push({ "id":id , "name": name, "songs": [] }) + return id; + } + throw "ID taken" } function playPlaylist(id) { From a3e6a17d350eb567a7a0f86ba4fdce78c1960b65 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 12:53:08 +0300 Subject: [PATCH 09/26] fixed test bug I accidentally changed the letters. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7f5b93c..876ad6e 100644 --- a/index.js +++ b/index.js @@ -136,7 +136,7 @@ function editPlaylist(PlaylistId, songId) { // your code here } -function PlaylistDuration(id) { +function playlistDuration(id) { // your code here } From 166ba9169ff73e82dfee92fe4fbdcf7c67683be0 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 13:05:59 +0300 Subject: [PATCH 10/26] playPlaylist added playPlaylist simplly loop that use playSong --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 876ad6e..83090c8 100644 --- a/index.js +++ b/index.js @@ -129,8 +129,11 @@ function createPlaylist(name, id=generatePlaylistId()) { } function playPlaylist(id) { - // your code here + for(let songId of findPlaylist(id).songs){ + playSong(songId) + } } +playPlaylist(1) function editPlaylist(PlaylistId, songId) { // your code here From 098a808317d92ea9e6dcb2ec71ba6e65be4288cb Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 13:08:35 +0300 Subject: [PATCH 11/26] fixed seconed in duration if the seconed were less than ten it would give 00:0 insted 00:00. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 83090c8..9038aeb 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ const player = { ], playSong(song) { console.log(`Playing ${song.title} from ${song.album} by ${song.artist} | ` - +((Math.floor(song.duration/60))<10? "0": "")+`${Math.floor(song.duration/60)}:${song.duration%60}.`) + +((Math.floor(song.duration/60))<10? "0": "")+`${Math.floor(song.duration/60)}:` +((song.duration%60)<10? "0": "")+`${song.duration%60}.`) } } From d3345c9c3418b5e6e87bfa5e9dd2cef8cd80118a Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 18:17:49 +0300 Subject: [PATCH 12/26] editPlaylist added editPlaylist func. --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9038aeb..abbe1ff 100644 --- a/index.js +++ b/index.js @@ -133,10 +133,18 @@ function playPlaylist(id) { playSong(songId) } } -playPlaylist(1) function editPlaylist(PlaylistId, songId) { - // your code here + let playlistIndex=player.playlists.indexOf(findPlaylist(PlaylistId)); + findSong(songId); + if(player.playlists[playlistIndex].songs.indexOf(songId)===(-1)){ + player.playlists[playlistIndex].songs.push(songId); + }else{ + player.playlists[playlistIndex].songs.splice(player.playlists[playlistIndex].songs.indexOf(songId),1); + } + if(player.playlists[playlistIndex].songs.length===0){ + removePlaylist(PlaylistId); + } } function playlistDuration(id) { From b9a89ac2fc62165a6ad61c984fca0976228a9521 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 21:11:00 +0300 Subject: [PATCH 13/26] playlistDuration added playlistDuration func. --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index abbe1ff..1a50ebe 100644 --- a/index.js +++ b/index.js @@ -148,7 +148,11 @@ function editPlaylist(PlaylistId, songId) { } function playlistDuration(id) { - // your code here + let plDuration=0; + for(let songID of findPlaylist(id).songs){ + plDuration+=(findSong(songID).duration); + } + return (plDuration); //why is that in sec ?? } function searchByQuery(query) { From 9652f2fbc0923332f43cf960b9b08d671a564b5c Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 21:48:55 +0300 Subject: [PATCH 14/26] searchByQuery added searchByQuery func. --- index.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 1a50ebe..58b2ec0 100644 --- a/index.js +++ b/index.js @@ -156,7 +156,31 @@ function playlistDuration(id) { } function searchByQuery(query) { - // your code here + const QUERY=query.toUpperCase(); + const queryObj={"songs":[],"playlists":[]} + for(let song of player.songs) { + if(song.title.toUpperCase().includes(QUERY) + ||song.artist.toUpperCase().includes(QUERY) + ||song.album.toUpperCase().includes(QUERY)){ + queryObj.songs.push(song); + } + } + for(let playlist of player.playlists){ + if(playlist.name.toUpperCase().includes(QUERY)){ + queryObj.playlists.push(playlist); + } + } + queryObj.songs.sort(function(a, b) { + let titleA = a.title.toUpperCase(); + let titleB = b.title.toUpperCase(); + if (titleA < titleB) { + return -1; + } + if (titleA > titleB) { + return 1; + } + }); + return queryObj; } function searchByDuration(duration) { From 3d48c183dde1db25c09706e877456343cb363f87 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 23:01:08 +0300 Subject: [PATCH 15/26] searchByDuration works...need check to see if could be improve --- index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 58b2ec0..1dd7ab9 100644 --- a/index.js +++ b/index.js @@ -184,9 +184,25 @@ function searchByQuery(query) { } function searchByDuration(duration) { - // your code here + let sec=durationToSeconds(duration); + let allDurationArr=[]; + let matchingArr=[]; //matching array that saves the song and playlist parallel(they will have the same index) to the duration array(allDurationArr) + let closestDuration=player.songs[0].duration; + for(let song of player.songs){ + allDurationArr.push(song.duration); + matchingArr.push(song); + } + for(let playlist of player.playlists){ + allDurationArr.push(playlistDuration(playlist.id)); + matchingArr.push(playlist); + } + for(let dur of allDurationArr){ + if(Math.abs(dur-sec) Date: Thu, 9 Sep 2021 23:37:25 +0300 Subject: [PATCH 16/26] checkDurationInput added checkDurationInput func. that checks if the durattion is in the correct format. apllyed it in functions that use duration as input --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index 1dd7ab9..7b5322d 100644 --- a/index.js +++ b/index.js @@ -90,9 +90,18 @@ newSongId+=1; return newSongId; } function durationToSeconds(duration){ + checkDurationInput(duration) return((parseInt(duration[0])*10)+parseInt(duration[1]))*60 +parseInt(duration[3]*10)+parseInt(duration[4]) } +function checkDurationInput(duration){ + console.log(0<=parseInt(duration[0])) + console.log(duration[2]===":") + if(0<=parseInt(duration[0])&&parseInt(duration[0])<=9&&0<=parseInt(duration[1])&&parseInt(duration[1])<=9 + &&duration[2]===":"&&0<=parseInt(duration[3])&&parseInt(duration[3])<6&&0<=parseInt(duration[4])&&parseInt(duration[4])<=9&&duration.length===5){ + return true + }else throw 'duration is not in the correct format...(this is the format-"00:00")' +} function addSong(title, album, artist, duration, id=generateSongId()) { try{ findSong(id) @@ -184,6 +193,7 @@ function searchByQuery(query) { } function searchByDuration(duration) { + checkDurationInput(duration); let sec=durationToSeconds(duration); let allDurationArr=[]; let matchingArr=[]; //matching array that saves the song and playlist parallel(they will have the same index) to the duration array(allDurationArr) From 52a8515ddaca5bd12e4391b36a525a35c7b95031 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Thu, 9 Sep 2021 23:38:43 +0300 Subject: [PATCH 17/26] deleted unnecessary variables deleted unnecessary variables --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index 7b5322d..07b3b50 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,6 @@ const player = { } function findSong(id){ - let notValId=true; for(let song of player.songs){ if (song.id===id){ return song; @@ -65,7 +64,6 @@ function findSong(id){ } function findPlaylist(id){ - let notValId=true; for(let Playlist of player.playlists){ if (Playlist.id===id){ return Playlist; From ac44e059161c1c60ec9969c548dfad7d7854f819 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 00:13:15 +0300 Subject: [PATCH 18/26] improved readablity and order. --- index.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 07b3b50..b0212de 100644 --- a/index.js +++ b/index.js @@ -82,24 +82,27 @@ function removeSong(id) { playlist.songs.splice(playlist.songs.indexOf(id),1) } } + let newSongId=10; function generateSongId(){ -newSongId+=1; -return newSongId; + newSongId+=1; + return newSongId; } + function durationToSeconds(duration){ checkDurationInput(duration) return((parseInt(duration[0])*10)+parseInt(duration[1]))*60 +parseInt(duration[3]*10)+parseInt(duration[4]) } -function checkDurationInput(duration){ - console.log(0<=parseInt(duration[0])) - console.log(duration[2]===":") - if(0<=parseInt(duration[0])&&parseInt(duration[0])<=9&&0<=parseInt(duration[1])&&parseInt(duration[1])<=9 - &&duration[2]===":"&&0<=parseInt(duration[3])&&parseInt(duration[3])<6&&0<=parseInt(duration[4])&&parseInt(duration[4])<=9&&duration.length===5){ + +function checkDurationInput(duration){ // checks digits(maximum is 59:59/minimum is 00:00),:,length. + if(0<=parseInt(duration[0])&&parseInt(duration[0])<6&&0<=parseInt(duration[1])&&parseInt(duration[1])<=9 + &&duration[2]===":"&&0<=parseInt(duration[3])&&parseInt(duration[3])<6&&0<=parseInt(duration[4]) + &&parseInt(duration[4])<=9&&duration.length===5){ return true }else throw 'duration is not in the correct format...(this is the format-"00:00")' } + function addSong(title, album, artist, duration, id=generateSongId()) { try{ findSong(id) @@ -141,7 +144,7 @@ function playPlaylist(id) { } } -function editPlaylist(PlaylistId, songId) { +function editPlaylist(PlaylistId, songId) { // to check readability!! let playlistIndex=player.playlists.indexOf(findPlaylist(PlaylistId)); findSong(songId); if(player.playlists[playlistIndex].songs.indexOf(songId)===(-1)){ @@ -159,7 +162,7 @@ function playlistDuration(id) { for(let songID of findPlaylist(id).songs){ plDuration+=(findSong(songID).duration); } - return (plDuration); //why is that in sec ?? + return (plDuration); } function searchByQuery(query) { @@ -168,8 +171,9 @@ function searchByQuery(query) { for(let song of player.songs) { if(song.title.toUpperCase().includes(QUERY) ||song.artist.toUpperCase().includes(QUERY) - ||song.album.toUpperCase().includes(QUERY)){ - queryObj.songs.push(song); + ||song.album.toUpperCase().includes(QUERY)) + { + queryObj.songs.push(song); } } for(let playlist of player.playlists){ From 93a50a9f9fb411bf84bad30d06ffc2a89167eb13 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 00:15:07 +0300 Subject: [PATCH 19/26] added two func for readablity and order sortByTitle sortByName both for searchByQuery func. --- index.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index b0212de..4184286 100644 --- a/index.js +++ b/index.js @@ -181,19 +181,33 @@ function searchByQuery(query) { queryObj.playlists.push(playlist); } } - queryObj.songs.sort(function(a, b) { - let titleA = a.title.toUpperCase(); - let titleB = b.title.toUpperCase(); - if (titleA < titleB) { - return -1; - } - if (titleA > titleB) { - return 1; - } - }); + queryObj.songs.sort(sortByTitle); + queryObj.playlists.sort(sortByName); return queryObj; } +function sortByTitle(a, b) { + let titleA = a.title.toUpperCase(); + let titleB = b.title.toUpperCase(); + if (titleA < titleB) { + return -1; + } + if (titleA > titleB) { + return 1; + } +} + +function sortByName(a, b) { + let nameA = a.name.toUpperCase(); + let nameB = b.name.toUpperCase(); + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } +} + function searchByDuration(duration) { checkDurationInput(duration); let sec=durationToSeconds(duration); From cce4de4bba244c971b5de280e86c251ad4d7e254 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 09:57:13 +0300 Subject: [PATCH 20/26] Update README.md --- README.md | 101 +++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 290ef50..c5e0be3 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,30 @@ -# MP3 Player - Second Weekend Assignment -You are going to implement an MP3 player. +# MP3 Player : +this project suppose to demonstrate simple MP3 Player. -## Instructions -1. Fork this repo into your account. -2. Clone the forked repo to your computer. -3. Execute `npm install` in the project folder to install the [tests](#testing). -4. Create a new git branch for your work. -5. Complete the project [requirements](#requirements). -6. Remember to push your commits regularly to GitHub. -7. Submit your work (explanation [below](#submission)) -8. Good luck & have fun! +## functions you should know about: +- `playSong` - Gets a song ID, and plays it by printing it's data. +- `removeSong` - Gets a song ID, and removes it from the player (from songs and playlists). +- `addSong` - Gets a title, album, artist, duration(`mm:ss`) & ID(optional). +- `removePlaylist` - Gets a playlist ID. Remove the playlist from the player. +- `createPlaylist` - Gets a name & ID(optional). Creates a new, empty playlist with the given details. +- `playPlaylist` - Gets a playlist ID. Plays all songs in the playlist. +- `editPlaylist` - Gets a playlist ID & a song ID: -If the song ID exists in the playlist, removes it. + -If it was the only song in the playlist, also deletes the playlist. + -If the song ID does not exist in the playlist, adds it to the end of the playlist. +- `playlistDuration` - Gets a playlist ID. Returns the total duration of the entire playlist. +- `searchByQuery` - Gets a query string. search in songs(title,album and artist) and playlists. +- `searchByDuration` - Gets a duration in `mm:ss` format (for example 01:03). Returns the song, or playlist, with the closest duration to what was given. -## Requirements -The player itself is an object that has: -- `songs`: an array of songs -- `playlists`: an array of playlists -- `playSong`: a method that plays a song. -It receives a song object and should print the following format `"Playing {song.title} from {song.album} by {song.artist} | {song.duration}."` (replace the stuff inside the `{}` with the real values). -The song duration should be in `mm:ss` format (for example 02:40). +__Note__: The functions are not yet merge to the main branch. -A song object has: -- `id`: a unique ID (a number) -- `title`: a title -- `album`: album title -- `artist`: artist name -- `duration`: duration (number, in seconds) -A playlist object has: -- `id`: a unique ID (a number) -- `name`: a name -- `songs`: an array of song IDs +## additions +Nulla volutpat, ante sed dignissim viverra, mauris dui varius augue, id pellentesque diam erat at quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque dictum fermentum purus, in fermentum arcu pellentesque a. -You are asked to implement the following functions: -- `playSong` - Gets a song ID. Uses `player.playSong` to play the song with the given ID. -- `removeSong` - Gets a song ID. Removes the song with the given ID from the player (from songs and playlists). -- `addSong` - Gets a title, album, artist, duration & ID. Adds a new song with given properties to the player. The ID is optional, and if omitted should be automatically generated. The song duration should be in `mm:ss` format (for example 06:27). Returns the ID of the new song. -- `removePlaylist` - Gets a playlist ID. Remove the playlist with the given ID from the player (does not delete the songs inside it). -- `createPlaylist` - Gets a name & ID. Creates a new, empty playlist with the given details. The ID is optional, and if omitted should be automatically generated. Returns the ID of the new playlist. -- `playPlaylist` - Gets a playlist ID. Plays all songs in the specified playlist, in the order the appear in the playlist. -- `editPlaylist` - Gets a playlist ID & a song ID. If the song ID exists in the playlist, removes it. If it was the only song in the playlist, also deletes the playlist. If the song ID does not exist in the playlist, adds it to the end of the playlist. -- `playlistDuration` - Gets a playlist ID. Returns the total duration of the entire playlist with the given ID. -- `searchByQuery` - Gets a query string. Returns a results object, which has: - - `songs`: an array of songs in which either title or album or artist contain the query string. The songs should be sorted by their titles. - - `playlists`: an array of playlists in which the name contains the query string. The playlists should be sorted by their names. - - The comparison in both cases should be case-insensitive. -- `searchByDuration` - Gets a duration in `mm:ss` format (for example 11:03). Returns the song, or playlist, with the closest duration to what was given. +__Note__: The functions are not yet merge to the main branch. -## Testing -We have added some automated tests for you to use. They will help you make sure your code covers the requirements. -To run the tests, execute `npm run test` in the project folder. - -__Note__: These tests might not cover everything. Don't just count on them. You should remain responsible and vigilant for other possible edge-cases. - - -## Grading -Your work will be graded based on the following considerations: -- The number of automatic tests you pass -- Readable and ordered code - - Spacing & indentation - - Indicative vairable/function names - - Comments (where necessary) -- Proper use of Git - - Granular commits - - Descriptive commit messages -- Extra features you might have added - - -## Submission -1. On GitHub, open a pull request from your branch to the main branch. -2. __Do not merge the pull request!__ -3. Add the user `Cyber4sPopo` as collaborator to your repo. -4. Submit a link to the pull request in Google Classroom. - - -## Important Tip -Try to work in small iterations. You've got a big and complex task ahead of you. Break it down into smaller tasks. Concentrate on making small progress every time. Do it step by step. - - -## Remarks -- The player object must be stored in a global variable called `player`. -- The function, method & property names should be __exactly__ as described above (for the tests to function). -- __Avoid code duplication!__ You are free to add as many extra functions as you like. -- Pay attention to edge-cases! Your code should throw errors when the user tries to do something invalid (delete a song that doesn't exist, etc.). -- You can use all the material you've learned so far, including extras you've learned on your own. -- Write your code in the `index.js` file. It contains a template which you can use as the basis for your code. \ No newline at end of file +### if you have anything to add or comment I would love it. From 37b730a8fd1e30d4b98df26fb498659fd5d929c1 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 10:03:21 +0300 Subject: [PATCH 21/26] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c5e0be3..551d5eb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # MP3 Player : this project suppose to demonstrate simple MP3 Player. +![image](https://user-images.githubusercontent.com/89573774/132813316-8c310d9f-ef3a-4223-bf49-b59422ba651a.png) -## functions you should know about: +## Basic functions you should know about: - `playSong` - Gets a song ID, and plays it by printing it's data. - `removeSong` - Gets a song ID, and removes it from the player (from songs and playlists). @@ -20,11 +21,11 @@ this project suppose to demonstrate simple MP3 Player. __Note__: The functions are not yet merge to the main branch. -## additions +## Additions Nulla volutpat, ante sed dignissim viverra, mauris dui varius augue, id pellentesque diam erat at quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque dictum fermentum purus, in fermentum arcu pellentesque a. __Note__: The functions are not yet merge to the main branch. -### if you have anything to add or comment I would love it. +### If you have anything to add or comment I would love it. From cdc283a465f305ef626dbf6601222909c2cfe6c2 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 10:09:31 +0300 Subject: [PATCH 22/26] changed throw text changed it so the format will be clearer --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4184286..d2ebeae 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ function checkDurationInput(duration){ // checks digits(maximum is 59:59/minim &&duration[2]===":"&&0<=parseInt(duration[3])&&parseInt(duration[3])<6&&0<=parseInt(duration[4]) &&parseInt(duration[4])<=9&&duration.length===5){ return true - }else throw 'duration is not in the correct format...(this is the format-"00:00")' + }else throw 'Duration is not in the correct format...This is the format-"mm:ss" (for example 03:13)' } function addSong(title, album, artist, duration, id=generateSongId()) { From ae8cfadc3973acf039d36cb895e20c08dd010d59 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 10:54:14 +0300 Subject: [PATCH 23/26] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 551d5eb..56f64fa 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ __Note__: The functions are not yet merge to the main branch. ## Additions -Nulla volutpat, ante sed dignissim viverra, mauris dui varius augue, id pellentesque diam erat at quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque dictum fermentum purus, in fermentum arcu pellentesque a. +- `shufflePlaylist` -play any playlist in random order. +- `autoPlay` - automatically play next song.(not added yet!) __Note__: The functions are not yet merge to the main branch. From ec95547aaee4a4e413a9b4d592d5c711cf3b6e81 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Sat, 11 Sep 2021 23:48:58 +0300 Subject: [PATCH 24/26] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 56f64fa..4864b69 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ this project suppose to demonstrate simple MP3 Player. ## Basic functions you should know about: -- `playSong` - Gets a song ID, and plays it by printing it's data. +- `playSong` - Gets a song ID and number of song to play automatically(optional), and plays it by printing it's data. - `removeSong` - Gets a song ID, and removes it from the player (from songs and playlists). - `addSong` - Gets a title, album, artist, duration(`mm:ss`) & ID(optional). - `removePlaylist` - Gets a playlist ID. Remove the playlist from the player. @@ -23,10 +23,14 @@ __Note__: The functions are not yet merge to the main branch. ## Additions - `shufflePlaylist` -play any playlist in random order. -- `autoPlay` - automatically play next song.(not added yet!) +- `autoPlay` - automatically play next song.(insted of adding it as new function I updated playSong so you can choose how many song you want it to play automatically(randomly),if you don't choose it plays only the song that match the ID.) __Note__: The functions are not yet merge to the main branch. +## bugs /errors +- The autoPlay adittion choose the songs the next song randomly from all the songs in the player…so if you don't have many songs it will probably repeat the same songs all the time! maybe even 2 or 3 times in a row. + + ### If you have anything to add or comment I would love it. From e053d7b2caa80799cea517a874d0231975e4a2b6 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Sun, 12 Sep 2021 11:42:21 +0300 Subject: [PATCH 25/26] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4864b69..73650bf 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,4 @@ __Note__: The functions are not yet merge to the main branch. ### If you have anything to add or comment I would love it. + From 364cd888b197d6ab560e06beb77e5179e8e8177e Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Sun, 12 Sep 2021 11:43:50 +0300 Subject: [PATCH 26/26] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index d2ebeae..439cdbc 100644 --- a/index.js +++ b/index.js @@ -242,3 +242,4 @@ module.exports = { searchByQuery, searchByDuration, } +