Socket
Socket
Sign inDemoInstall

array-iter-next-crnt

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-iter-next-crnt

Get array items one-by-one and remember the current one.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
8.75 kB
Created
Weekly downloads
 

Readme

Source

array-iter-next-crnt

Get array items one-by-one and remember the current one.

Usage

from test/take2dict.js:

var iter = require('array-iter-next-crnt'), list, it, dict,
  expectEqual = require('equal-pmb'), expected;

list = [ 'animals', 3, 'bird', 'cat', 'horse',
  'tooFew', 9001,
  'empty', 0,
  'alpha', 5, 'a', 'b', 'c',    // misleading notation in order to
  'nums', 0, 1, 2, 3, 4,        // show that it doesn't matter
  'fruit', 2, 'banana', 'pear',
  ];

it = iter(list);
dict = {};
it.each(function (key) {
  expectEqual(it, this);
  expectEqual(it.crnt, key);
  var nextUp = it.peek(), howMany;
  expectEqual(it.next(), it);
  howMany = it.crnt;
  expectEqual(nextUp, howMany);
  dict[key] = it.take(howMany);
});

expected = {
  animals: [ 'bird', 'cat', 'horse' ],
  tooFew: false,
  empty: [],
  alpha: [ 'a', 'b', 'c', 'nums', 0 ],    // took 5, as expected.
  '1': [ 3, 4 ],
  fruit: [ 'banana', 'pear' ],
};
expectEqual(dict, expected);

In scenarios where you know that all your values are truthy and you don't mind coding style:

while (x = myIter()) { console.log(x); }

Known issues

  • needs more/better tests and docs

 

License

ISC

Keywords

FAQs

Last updated on 11 Mar 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc