Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
483 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var isIndex = require('./_isIndex');
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * The base implementation of `_.nth` which doesn't coerce arguments.
|
---|
| 5 | *
|
---|
| 6 | * @private
|
---|
| 7 | * @param {Array} array The array to query.
|
---|
| 8 | * @param {number} n The index of the element to return.
|
---|
| 9 | * @returns {*} Returns the nth element of `array`.
|
---|
| 10 | */
|
---|
| 11 | function baseNth(array, n) {
|
---|
| 12 | var length = array.length;
|
---|
| 13 | if (!length) {
|
---|
| 14 | return;
|
---|
| 15 | }
|
---|
| 16 | n += n < 0 ? length : 0;
|
---|
| 17 | return isIndex(n, length) ? array[n] : undefined;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | module.exports = baseNth;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.