Giter VIP home page Giter VIP logo

list-range's Introduction

list-range

Return an array of values within range, determined by range(start, stop[, step])
ES6 implementation of Python built-in range() function

Build Status Coverage Status Codebeat badge Codacy Badge Code Climate

NPM

Features

  • ES6
  • Zero dependencies
  • 100% test code coverage

Rules

  • start and step are optional
  • If the step argument is omitted, it defaults to 1
  • If the start argument is omitted, it defaults to 0
  • All the arguments must be integers
  • step can not be 0

Install

$ npm install list-range

Usage

const range = require('list-range')

console.log(range(10))
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(range(10, 10))
// []
console.log(range(3, 17, -2))
// []
console.log(range(1, 11))
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
console.log(range(0, 30, 5))
// [0, 5, 10, 15, 20, 25]
console.log(range(0, 10, 3))
// [0, 3, 6, 9]
console.log(range(10, -10, -1))
// [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
console.log(range(0))
// []
console.log(range(1, 0))
// []
console.log(range(21, -1, -2))
// [21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]
console.log(range(-1, -5, 1))
// []
console.log(range(-1, -5))
// []
console.log(range(-1, -5, -1))
// [-1, -2, -3, -4]
console.log(range(1.2, 5.76))
// Error: All the arguments must be integers
console.log(range(1, 10, 0))
// Error: Step value can not be 0

License

MIT © Nicolás Quiroz

list-range's People

Contributors

nhsz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.