Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!