mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-25 23:03:15 +00:00
More maths operators
This commit is contained in:
parent
f709641967
commit
64b665e706
|
@ -75,6 +75,18 @@ exports.min = makeNumericBinaryOperator(
|
||||||
function(a,b) {return Math.min(a,b);}
|
function(a,b) {return Math.min(a,b);}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
exports.fixed = makeNumericBinaryOperator(
|
||||||
|
function(a,b) {return Number.prototype.toFixed.call(a,b);}
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.precision = makeNumericBinaryOperator(
|
||||||
|
function(a,b) {return Number.prototype.toPrecision.call(a,b);}
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.exponential = makeNumericBinaryOperator(
|
||||||
|
function(a,b) {return Number.prototype.toExponential.call(a,b);}
|
||||||
|
);
|
||||||
|
|
||||||
exports.sum = makeNumericArrayOperator(
|
exports.sum = makeNumericArrayOperator(
|
||||||
function(accumulator,value) {return accumulator + value},
|
function(accumulator,value) {return accumulator + value},
|
||||||
0 // Initial value
|
0 // Initial value
|
||||||
|
@ -104,7 +116,7 @@ function makeNumericBinaryOperator(fnCalc) {
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function makeNumericArrayOperator(fnCalc,initialValue) {
|
function makeNumericArrayOperator(fnCalc,initialValue) {
|
||||||
initialValue = initialValue || 0;
|
initialValue = initialValue || 0;
|
||||||
|
@ -117,7 +129,7 @@ function makeNumericArrayOperator(fnCalc,initialValue) {
|
||||||
return fnCalc(accumulator,parseNumber(currentValue));
|
return fnCalc(accumulator,parseNumber(currentValue));
|
||||||
},initialValue))];
|
},initialValue))];
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function parseNumber(str) {
|
function parseNumber(str) {
|
||||||
return parseFloat(str) || 0;
|
return parseFloat(str) || 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user