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/COUNTBLANK.ts
-rw-r--r--
1109
 1import { isNull } 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 { Reducers } from "../../utils/Reducers";
 7import { AbstractFormula } from "../AbstractFormula";
 8import { FormulaName } from "../FormulaName";
 9
10export class COUNTBLANK extends AbstractFormula {
11  static SELF: COUNTBLANK = new COUNTBLANK();
12  NAME = FormulaName.COUNTBLANK;
13
14  internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
15    AbstractFormula.checkAtLeastLength(values.length, 1, this.NAME);
16    const counter = new Counter<Complex>();
17    values
18      .map(this.lookup)
19      .map(Mappers.flattenGridsToArrays) // 1, 2, [null, 1, "0", "Nope.", null]
20      .map(Mappers.ensureAllAreArrays) // [1], [2], [null, 1, "0", null]
21      .reduce(Reducers.join) // [1, 2, null, 1, "0", null]
22      .filter(isNull) // [null, null]
23      .map((value) => counter.count(value)); // [null, null]
24    return counter.getCount();
25  }
26}