source: trip-planner-front/node_modules/lodash/_createMathOperation.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1var baseToNumber = require('./_baseToNumber'),
2 baseToString = require('./_baseToString');
3
4/**
5 * Creates a function that performs a mathematical operation on two values.
6 *
7 * @private
8 * @param {Function} operator The function to perform the operation.
9 * @param {number} [defaultValue] The value used for `undefined` arguments.
10 * @returns {Function} Returns the new mathematical operation function.
11 */
12function 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
38module.exports = createMathOperation;
Note: See TracBrowser for help on using the repository browser.