@dtjv/randomize-array
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

randomize-array

Get each and every item in array, randomly.

This package is ESM only.

Install

$ npm install @dtjv/randomize-array

Usage

import { randomizeArray } from '@dtjv/randomize-array'

const getCharacter = randomizeArray(['🍩', '☕️', '🤓'])

getCharacter() //-> '☕️'
getCharacter() //-> '🤓'
getCharacter() //-> '🍩'
getCharacter() //-> undefined

API

randomizeArray(array, options?)

import { randomizeArray } from '@dtjv/randomize-array'

Returns a function, where each invocation returns a unique random value from array until all values are returned. Subsequent calls return undefined (unless the reset option is set to true, or restart is called).

array

Type: unknown[]
Default: []

Array of values to randomly access.

options

Type: Object

options.reset

Type: boolean
Default: false

Makes all values of array available for random selection once all values have been retrieved.

restart()

import { restart } from '@dtjv/randomize-array'

Makes all values of array available for random selection.

Author

License

MIT License

Package Sidebar

Install

npm i @dtjv/randomize-array

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

4.3 kB

Total Files

4

Last publish

Collaborators

  • dtjv