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/MAXA.ts
-rw-r--r--
1412
 1import { isNotNull } from "../../utils/Other";
 2import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
 3import { Complex } from "../../models/common/Types";
 4import { Converters } from "../../utils/Converters";
 5import { Mappers } from "../../utils/Mappers";
 6import { Reducers } from "../../utils/Reducers";
 7import { AbstractFormula } from "../AbstractFormula";
 8import { FormulaName } from "../FormulaName";
 9
10export class MAXA extends AbstractFormula {
11  static SELF: MAXA = new MAXA();
12  NAME = FormulaName.MAXA;
13
14  internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
15    AbstractFormula.checkAtLeastLength(values.length, 1, this.NAME);
16    const constructedValues = values
17      .map(this.lookup)
18      .map(Mappers.flattenGridsToArrays) // 1, "2", [null, 1, "99", "Text.", null, #REF!, true]
19      .map(Mappers.coerceNonArrayValuesToNumberOrThrow) // 1, 2, [null, 1, "99", "Text.", null, #REF!, true]
20      .map(Mappers.ensureAllAreArrays) // [1], [2], [null, 1, "99", "Text.", null, #REF!, true]
21      .reduce(Reducers.join) // [1, 2, null, 1, "99", "Text.", null, #REF!, true]
22      .filter(isNotNull) // [1, 2, 1, "99", "Text.", #REF!, true]
23      .map(Converters.textToZero) // [1, 2, 1, 0, 0, true]
24      .map(Converters.toNumber); // [1, 2, 1, 0, 0, 1]
25    if (constructedValues.length === 0) {
26      return 0;
27    }
28    return constructedValues.reduce(Reducers.max);
29  }
30}