middle-item
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

middle-item Travis CI Build Status

Get the middle item from an array.

NPM Badge

Install

npm install middle-item

Usage

const middleItem = require("middle-item")
 
middleItem([1, 2, 3])
//=> 2
 
middleItem([1, 2, 3, 4])
//=> 2
 
middleItem([1, 2, 3, 4], { leanRight: true })
//=> 3
 
middleItem.multiple([1, 2, 3, 4, 5], 3)
//=> [2, 3, 4]
 
middleItem.multiple([1, 2, 3, 4, 5], 2)
//=> [2, 3]
 
middleItem.multiple([1, 2, 3, 4, 5], 2, { leanRight: true })
//=> [3, 4]

API

middleItem(array, options?)

Get the middle item from an array.

array

Type: array

The array to get the middle item from.

options

Type: object

leanRight

Type: boolean
Default: false

If trying to get an even number of items from an array with an odd number of items (or vice versa), prefer the item on the right side of the middle rather than the left.

middleItem.multiple(array, count, options?)

Get items from the middle of an array.

array

Type: array

The array to get the middle items from.

count

Type: number

The amount of items to get.

options

Type: object

Same as middleItem

Package Sidebar

Install

npm i middle-item

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.14 kB

Total Files

6

Last publish

Collaborators

  • richienb