Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@writetome51/array-get-adjacent-at

2.0.2 • Public • Published

getAdjacentAt(
       startingIndex,
       howMany,
       array
): any[]

Beginning at startingIndex, returns howMany adjacent items from array.
Does not modify array. startingIndex can be negative or positive.

Examples

let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
getAdjacentAt(2, 3, arr);
// --> [3,4,5]
 
getAdjacentAt(4, 5, arr);
// --> [5, 6, 7, 8, 9]
 
// You can pass a negative index:
getAdjacentAt(-3, 2, arr);
// --> [8, 9]

Installation

npm i @writetome51/array-get-adjacent-at

Loading

import { getAdjacentAt } from '@writetome51/array-get-adjacent-at';

Install

npm i @writetome51/array-get-adjacent-at

DownloadsWeekly Downloads

6

Version

2.0.2

License

MIT

Unpacked Size

5.58 kB

Total Files

6

Last publish

Collaborators

  • avatar