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

@writetome51/array-get-and-remove-adjacent-at

2.0.0 • Public • Published

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

Beginning at startingIndex, it removes and returns howMany adjacent items from array.
startingIndex can be positive or negative.

Examples

let arr = [1,2,3,4,5,6];
getAndRemoveAdjacentAt(2, 3, arr);
// --> [3,4,5]
// arr is now [1,2,6]
 
arr = [1, 2, 3, 4, 5, 6, 7, 8];
getAndRemoveAdjacentAt(-4, 2, arr);
// --> [5,6]
// arr is now [1,2,3,4,7,8].
 
arr = [1, 2, 3, 4, 5, 6];
getAndRemoveAdjacentAt(-4, 5, arr); // requesting 1 too many items.
// Error: 'the array does not have enough items to fulfill your request'

Installation

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

Loading

import {getAndRemoveAdjacentAt} 
    from '@writetome51/array-get-and-remove-adjacent-at';

Install

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

DownloadsWeekly Downloads

3

Version

2.0.0

License

MIT

Unpacked Size

3.77 kB

Total Files

5

Last publish

Collaborators

  • avatar