mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Bump to v4.11.0.
This commit is contained in:
18
nthArg.js
18
nthArg.js
@@ -1,7 +1,10 @@
|
||||
import baseNth from './_baseNth';
|
||||
import rest from './rest';
|
||||
import toInteger from './toInteger';
|
||||
|
||||
/**
|
||||
* Creates a function that returns its nth argument.
|
||||
* Creates a function that returns its nth argument. If `n` is negative,
|
||||
* the nth argument from the end is returned.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -12,15 +15,18 @@ import toInteger from './toInteger';
|
||||
* @example
|
||||
*
|
||||
* var func = _.nthArg(1);
|
||||
*
|
||||
* func('a', 'b', 'c');
|
||||
* func('a', 'b', 'c', 'd');
|
||||
* // => 'b'
|
||||
*
|
||||
* var func = _.nthArg(-2);
|
||||
* func('a', 'b', 'c', 'd');
|
||||
* // => 'c'
|
||||
*/
|
||||
function nthArg(n) {
|
||||
n = toInteger(n);
|
||||
return function() {
|
||||
return arguments[n];
|
||||
};
|
||||
return rest(function(args) {
|
||||
return baseNth(args, n);
|
||||
});
|
||||
}
|
||||
|
||||
export default nthArg;
|
||||
|
||||
Reference in New Issue
Block a user