mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Ensure matches methods match arrays with duplicate values. [closes #2270]
This commit is contained in:
10
lodash.js
10
lodash.js
@@ -5010,10 +5010,12 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Recursively compare arrays (susceptible to call stack limits).
|
// Recursively compare arrays (susceptible to call stack limits).
|
||||||
if (isUnordered) {
|
if (seen) {
|
||||||
if (!arraySome(other, function(othValue) {
|
if (!arraySome(other, function(othValue, othIndex) {
|
||||||
return arrValue === othValue ||
|
if (!seen.has(othIndex) &&
|
||||||
equalFunc(arrValue, othValue, customizer, bitmask, stack);
|
(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
|
||||||
|
return seen.add(othIndex);
|
||||||
|
}
|
||||||
})) {
|
})) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
32
test/test.js
32
test/test.js
@@ -10437,9 +10437,23 @@
|
|||||||
|
|
||||||
source = { 'a': ['d', 'b'] };
|
source = { 'a': ['d', 'b'] };
|
||||||
actual = lodashStable.filter(objects, predicate);
|
actual = lodashStable.filter(objects, predicate);
|
||||||
|
|
||||||
assert.deepEqual(actual, []);
|
assert.deepEqual(actual, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should partial match arrays with duplicate values', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
|
||||||
|
source = { 'a': [2, 2] };
|
||||||
|
|
||||||
|
var actual = lodashStable.filter(objects, function(object) {
|
||||||
|
return _.isMatch(object, source);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(actual, [objects[1]]);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should partial match arrays of objects', function(assert) {
|
QUnit.test('should partial match arrays of objects', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
@@ -13630,6 +13644,15 @@
|
|||||||
assert.deepEqual(actual, []);
|
assert.deepEqual(actual, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should partial match arrays with duplicate values', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
|
||||||
|
actual = lodashStable.filter(objects, _.matches({ 'a': [2, 2] }));
|
||||||
|
|
||||||
|
assert.deepEqual(actual, [objects[1]]);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should partial match arrays of objects', function(assert) {
|
QUnit.test('should partial match arrays of objects', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
@@ -14075,6 +14098,15 @@
|
|||||||
assert.deepEqual(actual, []);
|
assert.deepEqual(actual, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should partial match arrays with duplicate values', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var objects = [{ 'a': [1, 2] }, { 'a': [2, 2] }],
|
||||||
|
actual = lodashStable.filter(objects, _.matchesProperty('a', [2, 2]));
|
||||||
|
|
||||||
|
assert.deepEqual(actual, [objects[1]]);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should partial match arrays of objects', function(assert) {
|
QUnit.test('should partial match arrays of objects', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user