mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Ensure _.divide and _.multiply return 1 when no arguments are specified. [closes #2405]
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -4783,13 +4783,14 @@
|
||||
*
|
||||
* @private
|
||||
* @param {Function} operator The function to perform the operation.
|
||||
* @param {number} [defaultValue] The value used for `undefined` arguments.
|
||||
* @returns {Function} Returns the new mathematical operation function.
|
||||
*/
|
||||
function createMathOperation(operator) {
|
||||
function createMathOperation(operator, defaultValue) {
|
||||
return function(value, other) {
|
||||
var result;
|
||||
if (value === undefined && other === undefined) {
|
||||
return 0;
|
||||
return defaultValue;
|
||||
}
|
||||
if (value !== undefined) {
|
||||
result = value;
|
||||
@@ -15533,7 +15534,7 @@
|
||||
*/
|
||||
var add = createMathOperation(function(augend, addend) {
|
||||
return augend + addend;
|
||||
});
|
||||
}, 0);
|
||||
|
||||
/**
|
||||
* Computes `number` rounded up to `precision`.
|
||||
@@ -15575,7 +15576,7 @@
|
||||
*/
|
||||
var divide = createMathOperation(function(dividend, divisor) {
|
||||
return dividend / divisor;
|
||||
});
|
||||
}, 1);
|
||||
|
||||
/**
|
||||
* Computes `number` rounded down to `precision`.
|
||||
@@ -15768,7 +15769,7 @@
|
||||
*/
|
||||
var multiply = createMathOperation(function(multiplier, multiplicand) {
|
||||
return multiplier * multiplicand;
|
||||
});
|
||||
}, 1);
|
||||
|
||||
/**
|
||||
* Computes `number` rounded to `precision`.
|
||||
@@ -15810,7 +15811,7 @@
|
||||
*/
|
||||
var subtract = createMathOperation(function(minuend, subtrahend) {
|
||||
return minuend - subtrahend;
|
||||
});
|
||||
}, 0);
|
||||
|
||||
/**
|
||||
* Computes the sum of the values in `array`.
|
||||
|
||||
Reference in New Issue
Block a user