Socket
Socket
Sign inDemoInstall

array-range

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-range

creates a new array with given range


Version published
Weekly downloads
177K
decreased by-9.98%
Maintainers
1
Install size
4.27 kB
Created
Weekly downloads
 

Readme

Source

array-range

stable

Tiny module to create a new dense array with the specified range.

var range = require('array-range')
range(3)       // -> [ 0, 1, 2 ]
range(1, 4)    // -> [ 1, 2, 3 ]

Mainly useful for functional programming. ES6 examples:

var array = require('array-range')

array(5).map( x => x*x )
// -> [ 0, 1, 4, 9, 16 ]

array(2, 10).filter( x => x%2===0 )
// -> [ 2, 4, 6, 8 ]

It can also be useful for creating a fixed size dense array. Cleaner than apply and does not create an intermediate array:

array(5)

//vs.

Array.apply(null, new Array(5))

Usage

NPM

array(start, end)

Creates a new dense array with a length of end-start elements. start is inclusive, end is exclusive. Negative values also work, e.g. range(-10, 10)

array(len)

Creates a new dense array with len number of elements, from zero to len-1.

If len is unspecified, it defaults to zero (empty array).

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Last updated on 09 Nov 2014

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