An open API service indexing awesome lists of open source software.

https://github.com/writetome51/array-get-and-remove-head-tail

These functions remove and return items from the beginning and end of the array, respectively
https://github.com/writetome51/array-get-and-remove-head-tail

array-manipulation elements javascript remove typescript

Last synced: 11 months ago
JSON representation

These functions remove and return items from the beginning and end of the array, respectively

Awesome Lists containing this project

README

          

# getAndRemoveHead\(
      numItems,
      array: T[]
): T[]

Removes and returns `numItems` from beginning of `array`.

# getAndRemoveTail\(
      numItems,
      array: T[]
): T[]

Removes and returns `numItems` from end of `array`.

## Examples
```
let arr = ['jim', 'todd', 'tony', 'barry', 'jill'];
let firstTwo = getAndRemoveHead(2, arr);

// firstTwo is ['jim', 'todd'] .
// arr is now ['tony', 'barry', 'jill'] .

let arr = ['jim', 'todd', 'tony', 'barry', 'jill'];
let lastThree = getAndRemoveTail(3, arr);

// lastThree is [ 'tony', 'barry', 'jill'] .
// arr is now ['jim', 'todd'] .
```

## Installation
`npm i @writetome51/array-get-and-remove-head-tail`

## Loading
```js
import {getAndRemoveHead, getAndRemoveTail}
from '@writetome51/array-get-and-remove-head-tail';
```