Okay, so I am pulling my hair out with this one. I am trying to make a function that will shuffle a virtual deck of cards. I saw examples online, but they were written in some syntax I am unfamiliar with. I really couldn't understand what was going on so I tried to write my own. Anyway, the way I am going about it, I am making a duplicate array and then randomly picking cards out of the first array and putting them into the second array one by one, then deleting the randomly selected card. Here's my code. The function is stopping once the length of the original array reaches 26.
shuffleDeck: function (deck) {
var newDeck = deck;
for (i = 0; i<newDeck.length;i++){
randomIndex = Math.floor(Math.random() * deck.length);
newDeck[i] = deck[randomIndex];
deck.splice(randomIndex,1);
console.log(deck.length);
}
return newDeck;
}