Git Product home page Git Product logo

array-range's Introduction

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.

array-range's People

Contributors

mattdesl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

array-range's Issues

Typed array/existing array as argument

Sometimes we deal with Uint32Array or alike.

Would that be nice to support both dtype argument and existing array as argument:

let arr = range(10, 'uint32')
range(11, 15, arr.subarray(0, 4))

?

Code problem

This code does not seem to be used

else if (!n0 && !n1) {
start = 0
end = 0
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.