Home Reference Source Test Repository

lib/tail.js

"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.tail = tail;

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

/**
 * Extracts the elements after the head of a list.
 *
 * @since v0.1.0
 * @param {Array} list - The array
 * @return {Array} - The tail of the list
 * @example
 *   tail(range(1, 11)) // => [2, 3, 4, 5, 6, 7, 8, 9, 10]
 *   tail([1, 2, 3]) // => [2, 3]
 *   tail([29, 10]) // => [10]
 *   tail([300]) // => [300]
 *   tail([]) //=> undefined
 *
 *   tail('abc') // => ['b, c']
 *   tail('ze') // => ['e']
 *   tail('q') // => ['q']
 *   tail('') //=> undefined
 */
function tail(list) {
    if (list.length === 0) return undefined;
    var results = [];
    list.length > 1 ? results.push.apply(results, _toConsumableArray(list.slice(1))) : results.push.apply(results, _toConsumableArray(list));
    return results;
}