Socket
Socket
Sign inDemoInstall

range-2018.js

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    range-2018.js

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


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 24 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc