Add _.invert and _.pairs.

Former-commit-id: b265ed3f148e5e951b8d061107bb376e0b2e651e
This commit is contained in:
John-David Dalton
2012-08-31 13:02:55 -07:00
parent e060d29337
commit 8c2d39fb82

View File

@@ -1286,6 +1286,26 @@
return object ? hasOwnProperty.call(object, property) : false; return object ? hasOwnProperty.call(object, property) : false;
} }
/**
* Invert the keys and values of an object. The values must be serializable.
*
* @static
* @memberOf _
* @alias methods
* @category Objects
* @param {Object} object The object to inspect.
* @returns {Array} Returns a new array of property names that have function values.
* @example
*
* var obj = {first: 'Moe', second: 'Larry', third: 'Curly'}
* // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...]
*/
var invert = createIterator({
'args': 'object',
'init': '{}',
'inLoop': 'result[value] = index'
});
/** /**
* Checks if `value` is a boolean (`true` or `false`) value. * Checks if `value` is a boolean (`true` or `false`) value.
* *
@@ -1878,7 +1898,7 @@
* }); * });
* // => { 'name': 'moe' } * // => { 'name': 'moe' }
*/ */
var pick = createIterator(dropIteratorOptions, { var pick = createIterator(omitIteratorOptions, {
'top': 'top':
'if (typeof callback != \'function\') {\n' + 'if (typeof callback != \'function\') {\n' +
' var prop,\n' + ' var prop,\n' +
@@ -4226,6 +4246,7 @@
lodash.indexOf = indexOf; lodash.indexOf = indexOf;
lodash.initial = initial; lodash.initial = initial;
lodash.intersection = intersection; lodash.intersection = intersection;
lodash.invert = invert;
lodash.invoke = invoke; lodash.invoke = invoke;
lodash.isArguments = isArguments; lodash.isArguments = isArguments;
lodash.isArray = isArray; lodash.isArray = isArray;
@@ -4256,6 +4277,7 @@
lodash.object = object; lodash.object = object;
lodash.omit = omit; lodash.omit = omit;
lodash.once = once; lodash.once = once;
lodash.pairs = pairs;
lodash.partial = partial; lodash.partial = partial;
lodash.pick = pick; lodash.pick = pick;
lodash.pluck = pluck; lodash.pluck = pluck;