list-range

1.0.6 • Public • Published

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

Package Sidebar

Install

npm i list-range

Weekly Downloads

0

Version

1.0.6

License

MIT

Last publish

Collaborators

  • nhsz