diff --git a/lodash.js b/lodash.js index 32c9f1f44..6c789e394 100644 --- a/lodash.js +++ b/lodash.js @@ -7789,7 +7789,8 @@ /** * This method is like `_.union` except that it accepts `iteratee` which is * invoked for each element of each `arrays` to generate the criterion by - * which uniqueness is computed. The iteratee is invoked with one argument: + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: * (value). * * @static @@ -7819,7 +7820,8 @@ /** * This method is like `_.union` except that it accepts `comparator` which - * is invoked to compare elements of `arrays`. The comparator is invoked + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked * with two arguments: (arrVal, othVal). * * @static diff --git a/test/test.js b/test/test.js index 4f2364465..8322d80e6 100644 --- a/test/test.js +++ b/test/test.js @@ -24541,6 +24541,13 @@ assert.deepEqual(args, [2.1]); }); + + QUnit.test('should output values from the first possible array', function(assert) { + assert.expect(1); + + var actual = _.unionBy([{ 'x': 1, 'y': 1 }], [{ 'x': 1, 'y': 2 }], 'x'); + assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]); + }); }()); /*--------------------------------------------------------------------------*/ @@ -24557,6 +24564,19 @@ assert.deepEqual(actual, [objects[0], objects[1], others[0]]); }); + + QUnit.test('should output values from the first possible array', function(assert) { + assert.expect(1); + + var objects = [{ 'x': 1, 'y': 1 }], + others = [{ 'x': 1, 'y': 2 }]; + + var actual = _.unionWith(objects, others, function(a, b) { + return a.x == b.x; + }); + + assert.deepEqual(actual, [{ 'x': 1, 'y': 1 }]); + }); }()); /*--------------------------------------------------------------------------*/