Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

random-array-iterator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-array-iterator

An iterator to iterate an array in random order with controls to requeue or dequeue elements during the iteration

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by13.51%
Maintainers
1
Weekly downloads
 
Created
Source

random-array-iterator

An iterator to iterate an array in random order with controls to requeue or dequeue elements during the iteration.

npm install random-array-iterator

Usage

const RandomArrayIterator = require('random-array-iterator')

const ite = new RandomArrayIterator([1, 2, 3, 4, 5])

for (const val of ite) {
  console.log(val) // random value

  // call requeue if you want to revisit this value is the same iteration
  if (someCondition) ite.requeue()

  // call dequeue if you want to remove the value from the iteration and array entirely
  if (someOtherCondition) ite.dequeue()
}

API

ite = new RandomArrayIterator(array)

Make a new iterator. Implements the JavaScript iterator interface.

ite.requeue()

Requeue the current value. Only valid to call during an iteration.

ite.dequeue()

Remove the current value from the array and iteration. Only valid to vall during an iteration.

ite.restart()

Restarts the iterator.

License

MIT

FAQs

Package last updated on 30 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc