@guanghechen/knuth-shuffledeprecated

Knuth shuffle

Usage no npm install needed!

<script type="module">
  import guanghechenKnuthShuffle from 'https://cdn.skypack.dev/@guanghechen/knuth-shuffle';
</script>

README

@guanghechen/knuth-shuffle


A typescript implementation of the Knuth-Shuffle algorithm.

Knuth-Shuffle is a shuffle algorithm, which can complete the shuffle in $O(N)$ time complexity on the basis of only using a constant level of extra space.

If you are interested in this algorithm, you can check here.

Install

  • npm

    npm install --save @guanghechen/knuth-shuffle
    
  • yarn

    yarn add @guanghechen/knuth-shuffle
    

Usage

  • Shuffle nums.

    import knuthShuffle from '@guanghechen/knuth-shuffle'
    
    knuthShuffle([1, 2, 3, 4, 5])
    
  • Shuffle complex data nodes.

    import knuthShuffle from '@guanghechen/knuth-shuffle'
    
    interface Node {
      name: string
      email: string
      age: number
    }
    
    const nodes: Node[] = [/*... omit ...*/]
    knuthShuffle(nodes)
    

Related