Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
I am getting undefined in my sufflle function

I am not sure what I am doing here, I am getting deck.length undefined in my shuffle funciton, can anyone tell me what I am doing wrong here? I tried many solutions to fix this problem and I can't understand why it is not working thanks.

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)


about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda