Remove multiVal param from _.invert.

This commit is contained in:
John-David Dalton
2016-01-23 15:11:44 -06:00
parent d99954133c
commit 552be2f5fb
2 changed files with 10 additions and 51 deletions

View File

@@ -10964,14 +10964,12 @@
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite property
* assignments of previous values unless `multiVal` is `true`.
* assignments of previous values.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to invert.
* @param {boolean} [multiVal] Allow multiple values per key.
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
* @returns {Object} Returns the new inverted object.
* @example
*
@@ -10979,24 +10977,10 @@
*
* _.invert(object);
* // => { '1': 'c', '2': 'b' }
*
* // with `multiVal`
* _.invert(object, true);
* // => { '1': ['a', 'c'], '2': ['b'] }
*/
function invert(object, multiVal, guard) {
function invert(object) {
return arrayReduce(keys(object), function(result, key) {
var value = object[key];
if (multiVal && !guard) {
if (hasOwnProperty.call(result, value)) {
result[value].push(key);
} else {
result[value] = [key];
}
}
else {
result[value] = key;
}
result[object[key]] = key;
return result;
}, {});
}