correct-index

1.0.0 • Public • Published

A lib to let you always get correct index of an array.

install

npm i correct-index --save

For example:

const correctIndex = require('correct-index')
const array = [0, 1, 2, 3]
 
correctIndex(0, array.length)   // return index as 0
correctIndex(-1, array.length)  // return index as 3
correctIndex(-4, array.length)  // return index as 0
correctIndex(5, array.length)   // return index as 1

/correct-index/

    Package Sidebar

    Install

    npm i correct-index

    Weekly Downloads

    2

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • ygjack