forked from suvelocity/Mp3PlayerTask
-
Notifications
You must be signed in to change notification settings - Fork 0
Cyber4s popo #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tomeryac
wants to merge
9
commits into
master
Choose a base branch
from
Cyber4sPopo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cyber4s popo #1
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
350835b
test 1+2
Tomeryac 06ee962
new test 1-2 and test 3-5
Tomeryac 077f7c5
test 6
Tomeryac ec6abf7
test 7-10
Tomeryac 9bb43db
test 11-13
Tomeryac 78eee07
test 13-15
Tomeryac d54cf5b
test 16-21
Tomeryac 1f23ddc
test 21-26
Tomeryac 24329c1
Update index.js
Tomeryac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,48 +48,248 @@ const player = { | |
| { id: 5, name: 'Israeli', songs: [4, 5] }, | ||
| ], | ||
| playSong(song) { | ||
| console.log(/* your code here */) | ||
| console.log("Playing "+player.songs[song].title+" from "+player.songs[song].album+" by "+player.songs[song].artist+" | "+songDuration(player.songs[song].duration)+"."); | ||
| }, | ||
| } | ||
|
|
||
| } | ||
| function playSong(id) { | ||
| // your code here | ||
| let num=songById(id); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not const? |
||
| if(num==-1) | ||
| throw("ID doesn't exist"); | ||
| player.playSong(num); | ||
| } | ||
|
|
||
| //check if the id exist in the playlist.song and remove the id | ||
| removeSong(4); | ||
| function removeSong(id) { | ||
| // your code here | ||
| } | ||
|
|
||
| let idR = songById(id); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idR? |
||
| if (idR==-1) | ||
| throw("ID doesn't exist!"); | ||
| player.songs.splice(idR,1); | ||
| for (let i = 0; i < player.playlists.length; i++) { | ||
| for (let j = 0; j < player.playlists[i].songs.length; j++) { | ||
| if(player.playlists[i].songs[j]==id){ | ||
| player.playlists[i].songs.splice(j,1); | ||
| } | ||
| } | ||
| } | ||
| } // check if the id exist and add the song to player.song | ||
| function addSong(title, album, artist, duration, id) { | ||
| // your code here | ||
| } | ||
| let temp = duration.split(":"); | ||
| let min = temp[0]*60; | ||
| let sec = temp[1]*1; | ||
| let ssduration = min + sec; | ||
|
|
||
| if (id == undefined) id = 1; | ||
| for (let i = 0; i < player.songs.length; i++) { | ||
| const song = player.songs[i]; | ||
| if(song.id > id) | ||
| id = song.id +1; | ||
| } | ||
|
|
||
| player.songs.forEach(song => { | ||
| if(song.id == id) | ||
| throw "exception"; | ||
| }); | ||
| player.songs.push({id:id,title:title,album:album,artist:artist,duration:ssduration}); | ||
| return id; | ||
| } | ||
| //check if the id exsist and remove it from the playlists. | ||
| function removePlaylist(id) { | ||
| // your code here | ||
| let found = false; | ||
| for (let i = 0; i < player.playlists.length && !found; i++) { | ||
| if(player.playlists[i].id==id){ | ||
| player.playlists.splice(i,1); | ||
| found = true; | ||
| } | ||
| } | ||
| if(!found){ | ||
| throw "ID does not exist"; | ||
| } | ||
| } //check if the id exsist and add new playlist to the playlists. | ||
| function createPlaylist(name, id){ | ||
| if(id==undefined) { | ||
| id = uniqueId(); | ||
| } | ||
| else{ | ||
| player.playlists.forEach(playlist => { | ||
| if(playlist.id==id) | ||
| throw "id exsist"; | ||
| }); | ||
| } | ||
| player.playlists.push({id:id, name:name, songs:[]}); | ||
| return id; | ||
| }// get a playlist id and play the song in the playlist. | ||
| function playPlaylist(id) { | ||
| let p; | ||
| player.playlists.forEach(playlist => { | ||
| if(playlist.id == id) | ||
| p = playlist; | ||
| }); | ||
| if(p != undefined) | ||
| { | ||
| p.songs.forEach(song => { | ||
| playSong(song); | ||
| }); | ||
| } | ||
| else{ | ||
| throw " id does not exist"; | ||
| } | ||
| } | ||
| //found the index of the playlist and the song. | ||
| function editPlaylist(playlistId, songId) { | ||
| let songIndex; | ||
| let playlistIndex; | ||
| for (let i = 0; i < player.playlists.length; i++) { | ||
| if (player.playlists[i].id == playlistId) { | ||
| playlistIndex = i; | ||
| for (let j = 0; j < player.playlists[i].songs.length; j++) { | ||
| if (player.playlists[i].songs[j] == songId) { | ||
| songIndex = j; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| if(songIndex != undefined){ // if the song exsist in the playlist and there is no more song remove the playlist | ||
| if(player.playlists[playlistIndex].songs.length == 1){ | ||
| player.playlists.splice(playlistIndex,1); | ||
|
|
||
| function createPlaylist(name, id) { | ||
| // your code here | ||
| } | ||
| else{ | ||
| player.playlists[playlistIndex].songs.splice(songIndex,1);// if the song exsist in the plqylist remove the song | ||
| } | ||
| } | ||
| else{ | ||
| player.playlists[playlistIndex].songs.push(songId);// if the song dosent exsist in the playlist add the song | ||
| } | ||
| songById(songId); | ||
|
|
||
| } | ||
| // function that gets id of a playlist and returns the sum of the duration of all the songs in the playlist. | ||
| function playlistDuration(id) { | ||
| let countDuration = 0; | ||
| let playlistIndex; | ||
| for (let i = 0; i< player.playlists.length; i++) { | ||
| if(player.playlists[i].id == id) | ||
| playlistIndex = i; | ||
| } | ||
|
|
||
| function playPlaylist(id) { | ||
| // your code here | ||
| for (let i = 0; i < player.playlists[playlistIndex].songs.length; i++) { | ||
| for (let j = 0; j < player.songs.length; j++) { | ||
| if(player.songs[j].id == player.playlists[playlistIndex].songs[i]) | ||
| countDuration += player.songs[j].duration; | ||
| } | ||
| } | ||
|
|
||
| function editPlaylist(playlistId, songId) { | ||
| // your code here | ||
| return countDuration; | ||
| } | ||
| //function that get a string and return an object with all the songs and the playlists that include the string. | ||
| function searchByQuery(query){ | ||
| let obj = { | ||
| songs:[], | ||
| playlists:[] | ||
| } | ||
| query = query.toLowerCase(); | ||
| for (let i = 0; i < player.songs.length; i++) { | ||
| const song = player.songs[i]; | ||
| if(song.title.toLowerCase().includes(query) || song.album.toLowerCase().includes(query) || song.artist.toLowerCase().includes(query)) | ||
| obj.songs.push(song); | ||
| } | ||
| for (let i = 0; i < player.playlists.length; i++) { | ||
| const playlist = player.playlists[i]; | ||
| if(playlist.name.toLowerCase().includes(query)) | ||
| obj.playlists.push(playlist); | ||
| } | ||
| obj.songs.sort(function(a, b){ | ||
| let titleA = a.title.toLowerCase(); | ||
| let titleB = b.title.toLowerCase(); | ||
| if (titleA < titleB) | ||
| { | ||
| return -1; | ||
| } | ||
| else if (titleA > titleB) | ||
| { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| }); | ||
|
|
||
| function playlistDuration(id) { | ||
| // your code here | ||
| } | ||
| obj.playlists.sort(function(a, b){ | ||
| let titleA = a.title.toLowerCase(); | ||
| let titleB = b.title.toLowerCase(); | ||
| if (titleA < titleB) | ||
| { | ||
| return -1; | ||
| } | ||
| else if (titleA > titleB) | ||
| { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| }); | ||
|
|
||
| function searchByQuery(query) { | ||
| // your code here | ||
| } | ||
| return obj; | ||
|
|
||
| } | ||
| //function that get a duration and check which playlist's/song's duration is closest to the duration picked. | ||
| function searchByDuration(duration) { | ||
| // your code here | ||
| let time = duration.split(":"); | ||
| let min = time[0]* 60; | ||
| let sec = time[1]*1; | ||
| let sumsec = min+sec; | ||
| let MinDiffrent = Math.abs(player.songs[0].duration - sumsec); | ||
| let obj = player.songs[0]; | ||
| for (let i = 0; i < player.songs.length; i++) { | ||
| const song = player.songs[i]; | ||
| if(MinDiffrent > Math.abs(song.duration - sumsec)){ | ||
| MinDiffrent = Math.abs(song.duration - sumsec); | ||
| obj = song; | ||
| } | ||
| } | ||
| for (let i = 0; i < player.playlists.length; i++) { | ||
| const playlist = player.playlists[i]; | ||
| if((Math.abs(playlistDuration(playlist.id) - sumsec)) < MinDiffrent){ | ||
| MinDiffrent = Math.abs(playlistDuration(playlist.id) - sumsec); | ||
| obj = playlist; | ||
| } | ||
| } | ||
|
|
||
| return obj; | ||
| } | ||
| //check the id and returns a new unused id. | ||
| function uniqueId(){ | ||
| let id =1; | ||
| player.playlists.forEach(playlist => { | ||
| if (playlist.id>id) { | ||
| id = playlist.id; | ||
|
|
||
| } | ||
|
|
||
| }); | ||
| return id+1; | ||
| } | ||
| // found the index in the array of the id | ||
| function songById(idT) | ||
| { | ||
| if (idT == undefined) idT = 0; | ||
| for (let i = 0; i < player.songs.length; i++) { | ||
| if(player.songs[i].id==idT) | ||
| return i; | ||
| } | ||
| throw ("non-existent song ID"); | ||
| } | ||
| // get duration and return it in min:sec format | ||
| function songDuration(duration){ | ||
| let min=0; | ||
| while(duration >=60) | ||
| { | ||
| min++; | ||
| duration-=60; | ||
| } | ||
| if(duration<10) | ||
| return "0"+min+":0"+duration; | ||
| return "0"+min+":"+duration; | ||
| } | ||
|
|
||
| module.exports = { | ||
|
|
@@ -105,3 +305,4 @@ module.exports = { | |
| searchByQuery, | ||
| searchByDuration, | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,5 +25,8 @@ | |
| "testMatch": [ | ||
| "**/__tests__/**/*.test.+(ts|tsx|js)" | ||
| ] | ||
| }, | ||
| "dependencies": { | ||
| "run": "^1.4.0" | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use string template and move player.songs[song] to a variable