mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 03:32:58 +03:00
27b6c8f521
* feat(tail): add tail function * feat(tail): add tail test code * feat(tail): add tail benchmark * feat(tail): add tail docs * Update docs/ko/reference/array/tail.md * Update docs/ko/reference/array/tail.md * Update docs/reference/array/tail.md * Update docs/reference/array/tail.md --------- Co-authored-by: Sojin Park <raon0211@gmail.com>
840 B
840 B
tail
Returns a new array with all elements except for the first.
This function takes an array and returns a new array containing all the elements except for the first one. If the input array is empty or has only one element, an empty array is returned.
Signature
function tail<T>(arr: [T]): [];
function tail(arr: []): [];
function tail<T, U>(arr: [T, ...U[]]): U[];
function tail<T>(arr: T[]): T[];
Parameters
arr
(T[]
): The array to get the tail of.
Returns
(T[]
): A new array containing all elements of the input array except for the first one.
Examples
const arr1 = [1, 2, 3];
const result = tail(arr1);
// result will be [2, 3]
const arr2 = [1];
const result2 = tail(arr2);
// result2 will be []
const arr3 = [];
const result3 = tail(arr3);
// result3 will be []