mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Ensure _.add and _.subtract return 0 when no arguments are given.
This commit is contained in:
@@ -13862,6 +13862,9 @@
|
|||||||
*/
|
*/
|
||||||
function add(augend, addend) {
|
function add(augend, addend) {
|
||||||
var result;
|
var result;
|
||||||
|
if (augend === undefined && addend === undefined) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (augend !== undefined) {
|
if (augend !== undefined) {
|
||||||
result = augend;
|
result = augend;
|
||||||
}
|
}
|
||||||
@@ -14072,6 +14075,9 @@
|
|||||||
*/
|
*/
|
||||||
function subtract(minuend, subtrahend) {
|
function subtract(minuend, subtrahend) {
|
||||||
var result;
|
var result;
|
||||||
|
if (minuend === undefined && subtrahend === undefined) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (minuend !== undefined) {
|
if (minuend !== undefined) {
|
||||||
result = minuend;
|
result = minuend;
|
||||||
}
|
}
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -997,6 +997,12 @@
|
|||||||
assert.strictEqual(_.add(-6, -4), -10);
|
assert.strictEqual(_.add(-6, -4), -10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should return `0` when no arguments are given', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
assert.strictEqual(_.add(), 0);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should not coerce arguments to numbers', function(assert) {
|
QUnit.test('should not coerce arguments to numbers', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
@@ -19196,6 +19202,12 @@
|
|||||||
assert.strictEqual(_.subtract(-6, -4), -2);
|
assert.strictEqual(_.subtract(-6, -4), -2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should return `0` when no arguments are given', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
assert.strictEqual(_.subtract(), 0);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should coerce arguments only numbers', function(assert) {
|
QUnit.test('should coerce arguments only numbers', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user