name:
src/main/js/formulas/statistical/MINA.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 MINA extends AbstractFormula {
11 static SELF: MINA = new MINA();
12 NAME = FormulaName.MINA;
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.min);
29 }
30}