Skip to content

writetome51/array-get-and-remove-head-tail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getAndRemoveHead<T>(
      numItems,
      array: T[]
): T[]

Removes and returns numItems from beginning of array.

getAndRemoveTail<T>(
      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

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published