1.2.3 • Published 8 months ago

jrange v1.2.3

Weekly downloads
14
License
MIT
Repository
github
Last release
8 months ago

jrange

license Coveralls NPM downloads

The range function of Python implemented using JavaScript.

range(start, end, step)

Install

npm i jrange -S

Usage

  • in browser
<script src="/dist/jrange.umd.js"></script>
<script>
  const list = jrange(10);
</script>
  • esm
import jrange from 'jrange';

const list = jrange(10, 1, -1);
  • CommonJS
const range = require('jrange'); // rename to range

const list = range(1, 100, 2);

arguments

/defaultrequired
start0no
end/yes
step1no

range(10) -> range(0, 10, 1)

range(1, 10) -> range(1, 10, 1)

different with python

  • In Python, the range function returns a Range Class, while jrange returns an Array.

python

rng = range(0, 10)

print(rng, type(rng))) # range(0, 10) <class 'range'>

# Convert to list
list = list(rng)

javascript

const list = jrange(0, 10)

console.log(Array.isArray(list)) // true
  • In Python, if the step is zero, the range function will throw an exception, while jrange will return an empty array.

python

range(1, 10, 0)

# ValueError: range() arg 3 must not be zero

javascript

jrange(1, 10, 0) // return []
1.2.0

8 months ago

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

8 months ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago