1.0.0 • Published 7 years ago

correct-index v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

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