@newdash/newdash
Version:
javascript/typescript utility library
41 lines (40 loc) • 1.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.drop = void 0;
const slice_1 = __importDefault(require("./slice"));
const toInteger_1 = __importDefault(require("./toInteger"));
/**
* Creates a slice of `array` with `n` elements dropped from the beginning.
*
* @since 5.16.0
* @category Array
* @param array The array to query.
* @param n The number of elements to drop.
* @returns Returns the slice of `array`.
* @example
*
* ```ts
* drop([1, 2, 3])
* // => [2, 3]
*
* drop([1, 2, 3], 2)
* // => [3]
*
* drop([1, 2, 3], 5)
* // => []
*
* drop([1, 2, 3], 0)
* // => [1, 2, 3]
* ```
*/
function drop(array, n = 1) {
const length = array == null ? 0 : array.length;
return length
? (0, slice_1.default)(array, n < 0 ? 0 : (0, toInteger_1.default)(n), length)
: [];
}
exports.drop = drop;
exports.default = drop;