Open
Description
// Get the last or last n elements in an array.
export default function (array, num = 1) {
if (!Array.isArray)
throw new Error('array-first expects an array as the first element');
if (typeof num !== 'number') throw new Error('num expects a number');
if (array.length === 0) return null;
return num === 1 ? array.pop() : array.slice(-num);
}
Metadata
Metadata
Assignees
Labels
No labels