0.0.1 • Published 6 years ago
array-previous v0.0.1
array-previous
Counterpart to Henrik Joreteg's array-next. Credit to him.
Super tiny module that returns the previous item in an array when given an item in the array.
If you give it the first item in the array and call previous it will loop around and give you the last.
installing
npm install array-previoushow to use
var previous = require('array-previous')
// our demo array
var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
// if none specified previous should return last
previous(arr) // returns 'g'
// when given an item in the array it returns the previous one
previous(arr, 'c') // returns 'b'
// it also loops if you give it the first item
previous(arr, 'a') // returns 'g'license
MIT
0.0.1
6 years ago