Avoid using the values toString method in _.invert if it’s not a function. [closes #3260]

This commit is contained in:
John-David Dalton
2018-02-02 17:08:43 -08:00
parent a1b53054d6
commit a73b92b58e

View File

@@ -13173,6 +13173,11 @@
* // => { '1': 'c', '2': 'b' }
*/
var invert = createInverter(function(result, value, key) {
if (value != null &&
typeof value.toString != 'function') {
value = nativeObjectToString.call(value);
}
result[value] = key;
}, constant(identity));
@@ -13203,6 +13208,11 @@
* // => { 'group1': ['a', 'c'], 'group2': ['b'] }
*/
var invertBy = createInverter(function(result, value, key) {
if (value != null &&
typeof value.toString != 'function') {
value = nativeObjectToString.call(value);
}
if (hasOwnProperty.call(result, value)) {
result[value].push(key);
} else {