commit
message
[AVERAGEIF] formula now accepts nested ranges/arrays
author
Ben Vogt <[email protected]>
date
2017-05-02 23:13:55
stats
3 file(s) changed,
4 insertions(+),
4 deletions(-)
files
package.json
src/Formulas/Statistical.ts
tests/Formulas/StatisticalTest.ts
1diff --git a/package.json b/package.json
2index 0d8f309..fda98d1 100644
3--- a/package.json
4+++ b/package.json
5@@ -5,7 +5,8 @@
6 "scripts": {
7 "clean": "rm -rf output/* && rm -rf test_output/*",
8 "build": "tsc && cp lib/parser.js output/",
9- "test": "./tests.sh"
10+ "test": "./tests.sh",
11+ "test:quiet": "./tests.sh | grep -v Test:"
12 },
13 "author": "vogtb <bvogt at gmail.com>",
14 "license": "MIT",
15diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
16index 593a019..32e4baa 100644
17--- a/src/Formulas/Statistical.ts
18+++ b/src/Formulas/Statistical.ts
19@@ -805,12 +805,11 @@ var MINA = function (...values) : number {
20 * average instead.
21 * @returns {number}
22 * @constructor
23- * TODO: This needs to take nested range values.
24 * TODO: This needs to also accept a third parameter "average_range"
25 */
26 var AVERAGEIF = function (...values) {
27 ArgsChecker.checkLength(values, 2);
28- var range = values[0];
29+ var range = Filter.flatten(values[0]);
30 var criteriaEvaluation = CriteriaFunctionFactory.createCriteriaFunction(values[1]);
31
32 var result = 0;
33diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
34index 32635bb..b8a29c4 100644
35--- a/tests/Formulas/StatisticalTest.ts
36+++ b/tests/Formulas/StatisticalTest.ts
37@@ -99,6 +99,7 @@ test("AVERAGEA", function(){
38
39
40 test("AVERAGEIF", function(){
41+ assertEquals(AVERAGEIF([1, 5, [5, 20, 100], [], [[2]], 10], '>2'), 28);
42 assertEquals(AVERAGEIF([1, 5, 10], '>2'), 7.5);
43 assertEquals(AVERAGEIF([1, 5, 10], ">4"), 7.5);
44 assertEquals(AVERAGEIF([1, 2, 2, 2, 2, 2, 2, 2], ">1"), 2);