Skip to content

what if use Array.slice() directly? #13

Open
@jxxl998

Description

@jxxl998
//  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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions