Last active
November 18, 2017 00:28
-
-
Save Spuffynism/5a43a249dcdee55b9d0f4dc01d216a0d to your computer and use it in GitHub Desktop.
better spotify playlist shuffling
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 characters
let shuffle = function (playlist) { | |
let shuffledPlaylist = [], | |
song; | |
while (playlist.length !== 0) { | |
song = Math.floor(Math.random() * playlist.length); | |
shuffledPlaylist.push(playlist[song]); | |
playlist.splice(song, 1); | |
} | |
return shuffledPlaylist; | |
}; | |
let play = function (playlist) { | |
for (var i = 0; i < playlist.length; i++) | |
console.log("Playing : " + playlist[i]); | |
}; | |
let playlist = ["Never", "Gonna", "Give", "You", "Up"]; | |
let shuffledPlaylist = shuffle(playlist); | |
play(shuffledPlaylist); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment