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

reverse-iterable-array

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reverse-iterable-array

A reverse-iterable array implementation based on the built-in Array object

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Weekly downloads
 
Created
Source

reverse-iterable-array

The ReverseIterableArray object is a reverse-iterable array implementation based on the built-in Array object.

Links:

See also:

Table of Contents

Install

ES Module

Download only the ES module file:

curl -O https://raw.githubusercontent.com/kleinfreund/reverse-iterable-array/master/src/reverse-iterable-array.mjs

Node.js package

(Requires Node version 8.5 or higher for ES module support)

Installs the node package as a dependency. It doesn’t have any dependencies itself.

npm install --save reverse-iterable-array

Note, that Node.js version 8.5 or higher is required, as it comes with experimental support for ES modules. If you don’t want to use it as an ES module, you will need to transpile the package yourself.

Usage

import { ReverseIterableArray } from './src/reverse-iterable-array.mjs';

const array = new ReverseIterableArray();

For more usage examples, have a look at kleinfreund.github.io/reverse-iterable-array.

You can also run the examples locally after cloning the repository:

npm install && npm run examples

Tests

… with Node’s experimental ES module feature:

npm test

Documentation

A ReverseIterableArray object iterates its elements in insertion or reverse-insertion order — a for...of loop returns the array’s elements for each iteration.

Constructor

Syntax
new ReverseIterableArray([iterable])

Parameters:

Usage
const array = new ReverseIterableArray();
Array
const array = new ReverseIterableArray([1, 2, 3]);
NodeList
const array = new ReverseIterableArray(...document.querySelectorAll('div'));

entries()

Returns an iterator containing the [index, element] pairs for each element in the ReverseIterableArray object in insertion order.

An iterator containing the same pairs in reverse-insertion order can be obtained with entries().reverseIterator().

Syntax
array.entries();

Return value:

A new ReverseIterableArray iterator object.

forEachReverse()

The forEachReverse() method executes a provided function once per each [index, element] pair in the ReverseIterableArray object, in reverse-insertion order.

Syntax
array.forEachReverse(callback[, thisArg]);

Parameters:

  • callback: Function to execute for each element.
  • thisArg: Value to use as this when executing callback.

keys()

Returns an iterator containing the indices for each element in the ReverseIterableArray object in insertion order.

An iterator containing the same indices in reverse-insertion order can be obtained with keys().reverseIterator().

Syntax
array.keys();

Return value:

A new ReverseIterableArray iterator object.

reverseIterator()

In theory, following the semantics of [Symbol.iterator](), this should be [Symbol.reverseIterator](). However, as a developer, I cannot define a well-known symbol myself and make use of it. In the future, the a proposal like The ReverseIterable Interface, by Lee Byron might make it’s way into the specification. For the time being, the reverseIterator() function serves the same purpose.

Syntax
array.reverseIterator();

Return value:

The array reverse-iterator function, which is the values().reverseIterator() function by default.

values()

Returns an iterator containing the elements in the ReverseIterableArray object in insertion order.

An iterator containing the same elements in reverse-insertion order can be obtained with values().reverseIterator().

Syntax
array.values();

Return value:

A new ReverseIterableArray iterator object.

[Symbol.iterator]()

Returns the array iterator function. By default, this is the values() function.

Syntax
array[Symbol.iterator]();

Return value:

The array iterator function, which is the entries() function by default.

Usage
const array = new ReverseIterableArray(1, 2, 4);

const iterator = array[Symbol.iterator]();

iterator.next().value;
//> 1

iterator.next().value;
//> 2

iterator.next().value;
//> 4

iterator.next().value;
//> undefined

[Symbol.toStringTag]()

The well-known symbol Symbol.toStringTag is accessed internally when callig Object.prototype.toString().

iteratorFor()

Returns an iterator containing the [index, element] pairs for each element in the ReverseIterableArray object in insertion order starting with the pair specified by the index parameter.

This allows starting iteration at a specific element in the array.

An iterator containing the same pairs in reverse-insertion order can be obtained with iteratorFor(index).reverseIterator().

Syntax
array.iteratorFor(index);

Parameters:

  • index: Required. The index of the element to start iterating from.

Return value:

A new ReverseIterableArray iterator object.

Keywords

FAQs

Package last updated on 11 Aug 2018

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