Returns numItems
from beginning of array
.
Returns numItems
from end of array
.
Neither function modifies array
.
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.
npm i @writetome51/array-get-head-tail
import {getHead, getTail} from '@writetome51/array-get-head-tail';