0.0.6 • Published 3 years ago

range-2018.js v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

range

return an array of Numbers, similar to such of a Python's

install and declare

node.js

npm i range-2018.js

v.12 or earlier

const range = require( 'range-2018.js' )

v.13+

import { range } from 'range-2018.js'

browser

install by copying the file, or just copy-paste the source code, i guess

import { range } from 'vendor/range/mod.js'

or

<script type='module' src='vendor/range/mod.js'></script>

usage examples

range( count )

N integers starting at 0

range( 10 ) >> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

range( start, stop )

all integers from X to Y (Y not included)

range( 1, 10 ) >> 1, 2, 3, 4, 5, 6, 7, 8, 9

range( -5, 5 ) >> -5, -4, -3, -2, -1, 0, 1, 2, 3, 4

range( start, stop, step )

all numbers from X to Y (Y not included), with Z as a distance

range( 1, 10, 2 ) >> 1, 3, 5, 7, 9

range( -2, 0, 0.3 ) >> -2, -1.7, -1.4, -1.1, -0.8, -0.5, -0.2

source code

const ceil_abs = N => Math.ceil( Math.abs( N ) )

const range = ( cnt_or_start = 0, stop = null, step = 1 ) =>
    ( null === stop )
 && [...Array( cnt_or_start ).keys( )]

 || [...Array( ceil_abs( ( stop - cnt_or_start ) / step ) )]
        .map( ( _, i ) => cnt_or_start + i * step )

mirrors

license

mit

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago