mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Make _.isEqual work with plain objects containing constructor properties with like object values and make _.invert assign arrays when using the multiValue flag. [closes #420]
This commit is contained in:
12
dist/lodash.js
vendored
12
dist/lodash.js
vendored
@@ -1340,6 +1340,7 @@
|
||||
|
||||
// non `Object` object instances with different constructors are not equal
|
||||
if (ctorA != ctorB &&
|
||||
!(hasOwnProperty.call(a, 'constructor') && hasOwnProperty.call(b, 'constructor')) &&
|
||||
!(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
|
||||
('constructor' in a && 'constructor' in b)
|
||||
) {
|
||||
@@ -5364,7 +5365,7 @@
|
||||
*
|
||||
* // with `multiValue`
|
||||
* _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true);
|
||||
* // => { 'fred': ['first', 'third'], 'barney': 'second' }
|
||||
* // => { 'fred': ['first', 'third'], 'barney': ['second'] }
|
||||
*/
|
||||
function invert(object, multiValue) {
|
||||
var index = -1,
|
||||
@@ -5376,11 +5377,12 @@
|
||||
var key = props[index],
|
||||
value = object[key];
|
||||
|
||||
if (multiValue && hasOwnProperty.call(result, value)) {
|
||||
if (typeof result[value] == 'string') {
|
||||
result[value] = [result[value]];
|
||||
if (multiValue) {
|
||||
if (hasOwnProperty.call(result, value)) {
|
||||
result[value].push(key);
|
||||
} else {
|
||||
result[value] = [key];
|
||||
}
|
||||
result[value].push(key);
|
||||
}
|
||||
else {
|
||||
result[value] = key;
|
||||
|
||||
Reference in New Issue
Block a user