array-previous

0.0.1 • Public • Published

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-previous

how 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

Readme

Keywords

Package Sidebar

Install

npm i array-previous

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

1.81 kB

Total Files

4

Last publish

Collaborators

  • henrygd