shuffle

shuffle

  • (anArray: array) => array
  1. Shuffle an array

    const arr = ['a', 'b', 'c']
    shuffle(arr) // is randomly ordered
    const arr = ['a', 'b', 'c']
    shuffle(arr) // is randomly ordered
    
    const arr = ['a', 'b', 'c']
    shuffle(arr) // is randomly ordered
    const arr = ['a', 'b', 'c']
    shuffle(arr) // is randomly ordered
    
  2. Sometimes we want to randomly order an array. Below, we have a list of players for a game of Uno. Let's randomize the turns.

    const players = ['grace', 'sam', 'jen']
    
    const turns = shuffle(players)
    console.log(turns) // is randomly ordered players
    const players = ['grace', 'sam', 'jen']
    
    const turns = shuffle(players)
    console.log(turns) // is randomly ordered players
    
    const players = ['grace', 'sam', 'jen']
    
    const turns = shuffle(players)
    console.log(turns) // is randomly ordered players
    const players = ['grace', 'sam', 'jen']
    
    const turns = shuffle(players)
    console.log(turns) // is randomly ordered players