An open API service indexing awesome lists of open source software.

https://github.com/writetome51/index-is-valid

Function returns true or false based on whether or not a certain index can exist in a certain array length
https://github.com/writetome51/index-is-valid

array index javascript typescript valid validation

Last synced: 12 months ago
JSON representation

Function returns true or false based on whether or not a certain index can exist in a certain array length

Awesome Lists containing this project

README

          

# indexIsValid(index, arrayLength): boolean

Returns true or false based on whether or not `index` can exist in `arrayLength`.
`index` can be negative or positive.

## Examples
```js
indexIsValid(0, 0); // --> false

indexIsValid(1, 1); // --> false

indexIsValid(-1, 1); // --> true

indexIsValid(1, 2); // --> true

indexIsValid(-2, 2); // --> true

indexIsValid(-3, 2); // --> false
```

## Installation
`npm i @writetome51/index-is-valid`

## Loading
```js
import { indexIsValid } from '@writetome51/index-is-valid';
```

## License
[MIT](https://choosealicense.com/licenses/mit/)