Package Exports
- runique-array
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (runique-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Randomly get unique item from array
Randomly get unique (non-repeating) item from array that's never the same as the previous.
Usage
const RandomList = require('runique-array')
const list = ['some', 'items', 'in', 'list']
/**
* Get random and unique item from array.
*/
const randomList = new RandomList(list)
randomList.getRandom() // -> 'items'
randomList.getRandom() // -> 'list'
randomList.getRandom() // -> 'some'
randomList.getRemainingLength() // -> 1
randomList.resetRemainingItems()
randomList.getRemainingLength() // -> 4
randomList.getRandom() // -> 'list'
randomList.getRandom() // -> 'items'
randomList.getRandom() // -> 'some'
randomList.getRandom() // -> 'in'
randomList.getRandom() // -> undefined (when we randomly get all items)
/**
* Reset array when we get all items.
*/
const randomList2 = new RandomList(list, { repeatLoop: true }) // Default false
randomList.getRandom() // -> 'list'
randomList.getRandom() // -> 'items'
randomList.getRandom() // -> 'some'
randomList.getRandom() // -> 'in'
randomList.getRandom() // -> 'some'
randomList.getRandom() // -> 'in'
randomList.getRandom() // -> 'list'
License
MIT