From 8c2d39fb82731dab7e356f8c975b066c9aeb1405 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 31 Aug 2012 13:02:55 -0700 Subject: [PATCH] Add `_.invert` and `_.pairs`. Former-commit-id: b265ed3f148e5e951b8d061107bb376e0b2e651e --- lodash.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index b56c3b48c..ebaca4809 100644 --- a/lodash.js +++ b/lodash.js @@ -1286,6 +1286,26 @@ 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. * @@ -1878,7 +1898,7 @@ * }); * // => { 'name': 'moe' } */ - var pick = createIterator(dropIteratorOptions, { + var pick = createIterator(omitIteratorOptions, { 'top': 'if (typeof callback != \'function\') {\n' + ' var prop,\n' + @@ -4226,6 +4246,7 @@ lodash.indexOf = indexOf; lodash.initial = initial; lodash.intersection = intersection; + lodash.invert = invert; lodash.invoke = invoke; lodash.isArguments = isArguments; lodash.isArray = isArray; @@ -4256,6 +4277,7 @@ lodash.object = object; lodash.omit = omit; lodash.once = once; + lodash.pairs = pairs; lodash.partial = partial; lodash.pick = pick; lodash.pluck = pluck;