@writetome51/array-get-head-tail
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

getHead(numItems, array: T[]): T[]

Returns numItems from beginning of array.

getTail(numItems, array: T[]): T[]

Returns numItems from end of array.

Neither function modifies array.

Examples

let arr = ['h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'];

getHead(3, arr);  
// --> ['h', 'i', 'j']

getTail(3, arr);  
// --> ['m', n', 'o']

getHead(8, arr);
// --> ['h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']

getTail(8, arr);
// --> ['h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']
    
getHead(9, arr);
// Error: the array does not have enough items to fulfill your request

getTail(9, arr);
// Error: The entered index is not valid. Whether positive or negative, it exceeds 
// the index range of the array.

Installation

npm i @writetome51/array-get-head-tail

Loading

import {getHead, getTail} from '@writetome51/array-get-head-tail';

Dependents (7)

Package Sidebar

Install

npm i @writetome51/array-get-head-tail

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

3.17 kB

Total Files

5

Last publish

Collaborators

  • writetome51