mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2025-12-06 02:30:46 -08:00
Modify output of some math operators for empty inputs (#9337)
* Initial commit * Adapt test to new behavior
This commit is contained in:
parent
059978ec63
commit
d58eec47c0
2 changed files with 6 additions and 2 deletions
|
|
@ -217,6 +217,10 @@ function makeNumericReducingOperator(fnCalc,initialValue,fnFinal) {
|
|||
source(function(tiddler,title) {
|
||||
result.push($tw.utils.parseNumber(title));
|
||||
});
|
||||
// We return an empty array if there are no input titles
|
||||
if(result.length === 0) {
|
||||
return [];
|
||||
}
|
||||
var value = result.reduce(function(accumulator,currentValue) {
|
||||
return fnCalc(accumulator,currentValue);
|
||||
},initialValue);
|
||||
|
|
|
|||
|
|
@ -372,13 +372,13 @@ describe("'reduce' and 'intersection' filter prefix tests", function() {
|
|||
it("should handle the variance operator", function() {
|
||||
expect(parseFloat(wiki.filterTiddlers("[tag[shopping]get[price]variance[]]").join(","))).toBeCloseTo(2.92);
|
||||
expect(parseFloat(wiki.filterTiddlers("[tag[food]get[price]variance[]]").join(","))).toBeCloseTo(3.367);
|
||||
expect(wiki.filterTiddlers(" +[variance[]]").toString()).toBe("NaN");
|
||||
expect(wiki.filterTiddlers(" +[variance[]]").toString()).toBe("");
|
||||
});
|
||||
|
||||
it("should handle the standard-deviation operator", function() {
|
||||
expect(parseFloat(wiki.filterTiddlers("[tag[shopping]get[price]standard-deviation[]]").join(","))).toBeCloseTo(1.71);
|
||||
expect(parseFloat(wiki.filterTiddlers("[tag[food]get[price]standard-deviation[]]").join(","))).toBeCloseTo(1.835);
|
||||
expect(wiki.filterTiddlers(" +[standard-deviation[]]").toString()).toBe("NaN");
|
||||
expect(wiki.filterTiddlers(" +[standard-deviation[]]").toString()).toBe("");
|
||||
});
|
||||
|
||||
it("should handle the :intersection prefix", function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue