source: imaps-frontend/node_modules/lodash-es/_createMathOperation.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import baseToNumber from './_baseToNumber.js';
2import baseToString from './_baseToString.js';
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
38export default createMathOperation;
Note: See TracBrowser for help on using the repository browser.