Triggers error if array
has no .length
, index
is not a valid index of array
(it is allowed
to be negative), or howMany
is not an integer greater than zero.
function getAdjacentAt(startingIndex, howMany, array) {
// validate arguments:
errorIfIndex_howMany_orArray_areNotValid(startingIndex, howMany, array);
if (startingIndex + howMany === 0) return arraySlice(startingIndex, array.length, array);
else return arraySlice(startingIndex, startingIndex + howMany, array);
}
npm i error-if-index-how-many-or-array-are-not-valid
import { errorIfIndex_howMany_orArray_areNotValid }
from 'error-if-index-how-many-or-array-are-not-valid';