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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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/21] 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 d22e6cf5335990643665b48e36b8ea70cf5f72c1 Mon Sep 17 00:00:00 2001 From: tsoriLache <89573774+tsoriLache@users.noreply.github.com> Date: Fri, 10 Sep 2021 10:49:38 +0300 Subject: [PATCH 20/21] shufflePlaylist this func. play any playlist in random order. --- index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.js b/index.js index 4184286..52a114d 100644 --- a/index.js +++ b/index.js @@ -229,6 +229,26 @@ function searchByDuration(duration) { } return matchingArr[allDurationArr.indexOf(closestDuration)]; } + +function shufflePlaylist(id){ + let shuffleArr=[]; + let indexArr=[]; + let randomIndex; + for(let i=0;i Date: Sat, 11 Sep 2021 22:45:58 +0300 Subject: [PATCH 21/21] added auto option added auto option to playSong func. this addition let you choose if you want the player to play songs automaticlly(you need to insert to the seconed parametr number-who many song you would like it to play) --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 52a114d..fc7fbbe 100644 --- a/index.js +++ b/index.js @@ -72,8 +72,9 @@ function findPlaylist(id){ throw "ID not found"; } -function playSong(id) { +function playSong(id,auto=1) { player.playSong(findSong(id)); + if(auto>1) playSong(player.songs[Math.floor(Math.random() * player.songs.length)].id,auto-1) } function removeSong(id) {