1.0.1 • Published 3 years ago
@guanghechen/knuth-shuffle v1.0.1
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)