| @@ 5259-5283 (lines=25) @@ | ||
| 5256 | * @param {number} [defaultValue] The value used for `undefined` arguments. |
|
| 5257 | * @returns {Function} Returns the new mathematical operation function. |
|
| 5258 | */ |
|
| 5259 | function createMathOperation(operator, defaultValue) { |
|
| 5260 | return function(value, other) { |
|
| 5261 | var result; |
|
| 5262 | if (value === undefined && other === undefined) { |
|
| 5263 | return defaultValue; |
|
| 5264 | } |
|
| 5265 | if (value !== undefined) { |
|
| 5266 | result = value; |
|
| 5267 | } |
|
| 5268 | if (other !== undefined) { |
|
| 5269 | if (result === undefined) { |
|
| 5270 | return other; |
|
| 5271 | } |
|
| 5272 | if (typeof value == 'string' || typeof other == 'string') { |
|
| 5273 | value = baseToString(value); |
|
| 5274 | other = baseToString(other); |
|
| 5275 | } else { |
|
| 5276 | value = baseToNumber(value); |
|
| 5277 | other = baseToNumber(other); |
|
| 5278 | } |
|
| 5279 | result = operator(value, other); |
|
| 5280 | } |
|
| 5281 | return result; |
|
| 5282 | }; |
|
| 5283 | } |
|
| 5284 | ||
| 5285 | /** |
|
| 5286 | * Creates a function like `_.over`. |
|
| @@ 12-36 (lines=25) @@ | ||
| 9 | * @param {number} [defaultValue] The value used for `undefined` arguments. |
|
| 10 | * @returns {Function} Returns the new mathematical operation function. |
|
| 11 | */ |
|
| 12 | function createMathOperation(operator, defaultValue) { |
|
| 13 | return function(value, other) { |
|
| 14 | var result; |
|
| 15 | if (value === undefined && other === undefined) { |
|
| 16 | return defaultValue; |
|
| 17 | } |
|
| 18 | if (value !== undefined) { |
|
| 19 | result = value; |
|
| 20 | } |
|
| 21 | if (other !== undefined) { |
|
| 22 | if (result === undefined) { |
|
| 23 | return other; |
|
| 24 | } |
|
| 25 | if (typeof value == 'string' || typeof other == 'string') { |
|
| 26 | value = baseToString(value); |
|
| 27 | other = baseToString(other); |
|
| 28 | } else { |
|
| 29 | value = baseToNumber(value); |
|
| 30 | other = baseToNumber(other); |
|
| 31 | } |
|
| 32 | result = operator(value, other); |
|
| 33 | } |
|
| 34 | return result; |
|
| 35 | }; |
|
| 36 | } |
|
| 37 | ||
| 38 | export default createMathOperation; |
|
| 39 | ||
| @@ 12-36 (lines=25) @@ | ||
| 9 | * @param {number} [defaultValue] The value used for `undefined` arguments. |
|
| 10 | * @returns {Function} Returns the new mathematical operation function. |
|
| 11 | */ |
|
| 12 | function createMathOperation(operator, defaultValue) { |
|
| 13 | return function(value, other) { |
|
| 14 | var result; |
|
| 15 | if (value === undefined && other === undefined) { |
|
| 16 | return defaultValue; |
|
| 17 | } |
|
| 18 | if (value !== undefined) { |
|
| 19 | result = value; |
|
| 20 | } |
|
| 21 | if (other !== undefined) { |
|
| 22 | if (result === undefined) { |
|
| 23 | return other; |
|
| 24 | } |
|
| 25 | if (typeof value == 'string' || typeof other == 'string') { |
|
| 26 | value = baseToString(value); |
|
| 27 | other = baseToString(other); |
|
| 28 | } else { |
|
| 29 | value = baseToNumber(value); |
|
| 30 | other = baseToNumber(other); |
|
| 31 | } |
|
| 32 | result = operator(value, other); |
|
| 33 | } |
|
| 34 | return result; |
|
| 35 | }; |
|
| 36 | } |
|
| 37 | ||
| 38 | module.exports = createMathOperation; |
|
| 39 | ||