Last active
August 29, 2015 13:57
Revisions
-
jonathanhculver revised this gist
Mar 22, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -57,4 +57,6 @@ var playlistModule = (function() { removeTrack: removeTrack, addTrack: addTrack, shuffleTracks: shuffleTracks }; })(); -
jonathanhculver revised this gist
Mar 22, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,6 @@ var playlistModule = (function() { tempArray.push(nextTrack); maxNum--; } return tempArray; } -
jonathanhculver revised this gist
Mar 22, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ var playlistModule = (function() { return tempArray; } /* private utility methods */ var markPlayed = function(index) { shuffleArray.splice(index, 1); } -
jonathanhculver revised this gist
Mar 22, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,6 @@ var playlistModule = (function() { } return tempArray; } /* utility methods */ @@ -59,4 +58,4 @@ var playlistModule = (function() { removeTrack: removeTrack, addTrack: addTrack, shuffleTracks: shuffleTracks }; -
jonathanhculver created this gist
Mar 22, 2014 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ var playlistModule = (function() { /* private var */ var tracksArray = [], shuffleArray = []; /* public methods */ var addTrack = function(uri) { tracksArray.push(uri); return tracksArray; } var removeTrack = function(uri) { var index = findTrackIndex(uri); tracksArray.splice(index, 1); return tracksArray; } var getTracks = function() { return tracksArray; } var shuffleTracks = function() { var tempArray = []; var maxNum = tracksArray.length; /* made a copy of the array */ shuffleArray = tracksArray.slice(0); for(var i=0, max = tracksArray.length; i<max; i++) { var randomNum = Math.floor(Math.random() * maxNum); var nextTrack = shuffleArray[randomNum]; markPlayed(randomNum); tempArray.push(nextTrack); maxNum--; } return tempArray; } /* utility methods */ var markPlayed = function(index) { shuffleArray.splice(index, 1); } var findTrackIndex = function(uri) { for(var i = 0; i< tracksArray.length; i++) { if(tracksArray[i] == uri) { return i; } } } //only return methods we want public return { getTracks: getTracks, removeTrack: removeTrack, addTrack: addTrack, shuffleTracks: shuffleTracks };