mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Add _.flip. [closes #1449]
This commit is contained in:
28
lodash.js
28
lodash.js
@@ -23,7 +23,8 @@
|
|||||||
PARTIAL_FLAG = 32,
|
PARTIAL_FLAG = 32,
|
||||||
PARTIAL_RIGHT_FLAG = 64,
|
PARTIAL_RIGHT_FLAG = 64,
|
||||||
ARY_FLAG = 128,
|
ARY_FLAG = 128,
|
||||||
REARG_FLAG = 256;
|
REARG_FLAG = 256,
|
||||||
|
FLIP_FLAG = 512;
|
||||||
|
|
||||||
/** Used to compose bitmasks for comparison styles. */
|
/** Used to compose bitmasks for comparison styles. */
|
||||||
var UNORDERED_COMPARE_FLAG = 1,
|
var UNORDERED_COMPARE_FLAG = 1,
|
||||||
@@ -3453,6 +3454,7 @@
|
|||||||
isCurry = bitmask & CURRY_FLAG,
|
isCurry = bitmask & CURRY_FLAG,
|
||||||
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
||||||
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
||||||
|
isFlip = bitmask & FLIP_FLAG,
|
||||||
Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
||||||
|
|
||||||
function wrapper() {
|
function wrapper() {
|
||||||
@@ -3505,6 +3507,8 @@
|
|||||||
|
|
||||||
if (argPos) {
|
if (argPos) {
|
||||||
args = reorder(args, argPos);
|
args = reorder(args, argPos);
|
||||||
|
} else if (isFlip) {
|
||||||
|
args.reverse();
|
||||||
}
|
}
|
||||||
if (isAry && ary < args.length) {
|
if (isAry && ary < args.length) {
|
||||||
args.length = ary;
|
args.length = ary;
|
||||||
@@ -7471,6 +7475,27 @@
|
|||||||
return baseDelay(func, wait, args);
|
return baseDelay(func, wait, args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that invokes `func` with arguments reversed.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function} func The function to flip arguments for.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var flipped = _.flip(function() {
|
||||||
|
* return _.toArray(arguments);
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* flipped('a', 'b', 'c')
|
||||||
|
* // => ['c', 'b', 'a']
|
||||||
|
*/
|
||||||
|
function flip(func) {
|
||||||
|
return createWrapper(func, FLIP_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that returns the result of invoking the provided
|
* Creates a function that returns the result of invoking the provided
|
||||||
* functions with the `this` binding of the created function, where each
|
* functions with the `this` binding of the created function, where each
|
||||||
@@ -11854,6 +11879,7 @@
|
|||||||
lodash.filter = filter;
|
lodash.filter = filter;
|
||||||
lodash.flatten = flatten;
|
lodash.flatten = flatten;
|
||||||
lodash.flattenDeep = flattenDeep;
|
lodash.flattenDeep = flattenDeep;
|
||||||
|
lodash.flip = flip;
|
||||||
lodash.flow = flow;
|
lodash.flow = flow;
|
||||||
lodash.flowRight = flowRight;
|
lodash.flowRight = flowRight;
|
||||||
lodash.functions = functions;
|
lodash.functions = functions;
|
||||||
|
|||||||
@@ -20617,6 +20617,7 @@
|
|||||||
'debounce',
|
'debounce',
|
||||||
'defer',
|
'defer',
|
||||||
'delay',
|
'delay',
|
||||||
|
'flip',
|
||||||
'memoize',
|
'memoize',
|
||||||
'modArgs',
|
'modArgs',
|
||||||
'modArgsSet',
|
'modArgsSet',
|
||||||
@@ -20740,7 +20741,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should throw an error for falsey arguments', function(assert) {
|
QUnit.test('should throw an error for falsey arguments', function(assert) {
|
||||||
assert.expect(24);
|
assert.expect(25);
|
||||||
|
|
||||||
_.each(rejectFalsey, function(methodName) {
|
_.each(rejectFalsey, function(methodName) {
|
||||||
var expected = _.map(falsey, _.constant(true)),
|
var expected = _.map(falsey, _.constant(true)),
|
||||||
|
|||||||
Reference in New Issue
Block a user