f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/main/js/formulas/statistical/COUNTA.ts
-rw-r--r--
1257
 1import { isNotNull } from "../../utils/Other";
 2import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
 3import { Complex } from "../../models/common/Types";
 4import { Counter } from "../../utils/Counter";
 5import { Mappers } from "../../utils/Mappers";
 6import { Predicates } from "../../utils/Predicates";
 7import { Reducers } from "../../utils/Reducers";
 8import { AbstractFormula } from "../AbstractFormula";
 9import { FormulaName } from "../FormulaName";
10
11export class COUNTA extends AbstractFormula {
12  static SELF: COUNTA = new COUNTA();
13  NAME = FormulaName.COUNTA;
14
15  internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
16    AbstractFormula.checkAtLeastLength(values.length, 1, this.NAME);
17    const counter = new Counter<Complex>();
18    values
19      .map(this.lookup)
20      .map(Mappers.flattenGridsToArrays) // 1, 2, [null, 1, "0", "Text.", null, #REF!]
21      .map(Mappers.ensureAllAreArrays) // [1], [2], [null, 1, "0", "Text.", null, #REF!]
22      .reduce(Reducers.join) // [1, 2, null, 1, "0", "Text.", null, #REF!]
23      .filter(isNotNull) // [1, 2, 1, "0", "Text.", #REF!]
24      .filter(Predicates.isNonError) // [1, 2, 1, "0", "Text."]
25      .map((value) => counter.count(value));
26    return counter.getCount();
27  }
28}