@writetome51/index-is-valid
v2.0.2
Published
Function returns true or false based on whether or not a certain index can exist in a certain array length
Downloads
119
Maintainers
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
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
import { indexIsValid } from '@writetome51/index-is-valid';