This package has been deprecated

Author message:

use @algorithm.ts/knuth-shuffle instead

@guanghechen/knuth-shuffle
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@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

Package Sidebar

Install

npm i @guanghechen/knuth-shuffle

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

5.99 kB

Total Files

6

Last publish

Collaborators

  • lemonclown