Skip to content

Javascript functions that remove items from either beginning or end of an array.

License

Notifications You must be signed in to change notification settings

writetome51/array-get-head-tail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';

About

Javascript functions that remove items from either beginning or end of an array.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published