Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
890 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var baseSlice = require('./_baseSlice'),
|
---|
| 2 | toInteger = require('./toInteger');
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * Creates a slice of `array` with `n` elements dropped from the beginning.
|
---|
| 6 | *
|
---|
| 7 | * @static
|
---|
| 8 | * @memberOf _
|
---|
| 9 | * @since 0.5.0
|
---|
| 10 | * @category Array
|
---|
| 11 | * @param {Array} array The array to query.
|
---|
| 12 | * @param {number} [n=1] The number of elements to drop.
|
---|
| 13 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
---|
| 14 | * @returns {Array} Returns the slice of `array`.
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * _.drop([1, 2, 3]);
|
---|
| 18 | * // => [2, 3]
|
---|
| 19 | *
|
---|
| 20 | * _.drop([1, 2, 3], 2);
|
---|
| 21 | * // => [3]
|
---|
| 22 | *
|
---|
| 23 | * _.drop([1, 2, 3], 5);
|
---|
| 24 | * // => []
|
---|
| 25 | *
|
---|
| 26 | * _.drop([1, 2, 3], 0);
|
---|
| 27 | * // => [1, 2, 3]
|
---|
| 28 | */
|
---|
| 29 | function drop(array, n, guard) {
|
---|
| 30 | var length = array == null ? 0 : array.length;
|
---|
| 31 | if (!length) {
|
---|
| 32 | return [];
|
---|
| 33 | }
|
---|
| 34 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
---|
| 35 | return baseSlice(array, n < 0 ? 0 : n, length);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | module.exports = drop;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.