GithubHelp home page GithubHelp logo

range's Introduction

range

JavaScript range implementation

Just a simple range implementation with flow annotations

Usage

range can either take 1, 2, or 3 arguments.

If supplied with one argument, it will be interpreted as the end of the range and return an array from 0 to end, not including end with a step of 1 If supplied with two arguments, range will go from start to end with a step of 1 as long as start is less than end. If supplied with three arguments, that are all integers the range will go from start to end in increments of step. If start is bigger than end then step will have to be negative to produce a result.

Examples:

import range from 'range';

console.log(range(10));
// > [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

console.log(range(-10));
// > []

console.log(range(0, 10));
// > [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

console.log(range(10, 0, -1));
// > [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ]

console.log(range(10, null, -1));
// > [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ]

console.log(range(10, null, 1));
// > [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

console.log(range(0, 10, 3));
// > [ 0, 3, 6, 9 ]

console.log(range(-10, 10, 5));
// > [ -10, -5, 0, 5 ]

range's People

Contributors

divinegod avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

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.