No estoy seguro de lo que estoy haciendo aquí, obtengo un deck.length indefinido en mi función de reproducción aleatoria, ¿alguien puede decirme qué estoy haciendo mal aquí? Probé muchas soluciones para solucionar este problema y no puedo entender por qué no funciona, gracias.
function buildDeck() { const suits = ['spades', 'hearts', 'diamonds', 'clubs']; const ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; const deck = [] for (i = 0; i < ranks.length; i++){ for (j = 0; j < suits.length; j++){ deck.push({rank: ranks[i], suit: suits[j], value: j + 0}) } } console.log(deck) return deck } buildDeck() function shuffle(deck){ shuffleDeck = deck console.log(deck) let currentIndex = deck.length let temporaryValue = null let randomIndex = null while (currentIndex =! 0 ){ randomIndex = Math.floor(Math.random()*currentIndex) currentIndex -- temporaryValue = shuffleDeck[currentIndex] shuffleDeck[currentIndex] = shuffleDeck [randomIndex] shuffleDeck[randomIndex] = temporaryValue } return shuffleDeck } shuffle(deck)