All files / libs/amalia-lang/formula/evaluate/shared/src/functions/numbers/max index.ts

100% Statements 42/42
100% Branches 1/1
100% Functions 2/2
100% Lines 40/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x 1x 67x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 68x 1x  
import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
 
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
 
export const numbersMax = new AmaliaFunctionDefault<number[], number>({
  name: AmaliaFunctionKeys.MAX,
  category: AmaliaFunctionCategory.NUMBERS,
  nbParamsRequired: 0,
  hasInfiniteParams: true,
  description: 'Return the maximum among parameters such as numbers, fields, properties, variables, formulas etc',
 
  exec: (...numbers) => Math.max(...numbers),
 
  params: [
    { name: 'param1', description: 'The first param to compare' },
    { name: 'param2', description: 'The second param to compare' },
    { name: 'paramN', description: 'The Nth param to compare' },
  ],
 
  examples: [
    {
      desc: 'Returns 8',
      formula: 'MAX(8, 3)' as AmaliaFormula,
      result: 8,
    },
    {
      desc: 'Returns 623',
      formula: 'MAX(10, 2, 0, 5, 623)' as AmaliaFormula,
      result: 623,
    },
    {
      desc: 'Returns the maximum between Commission and 0. This will return only positive Commission.',
      formula: 'MAX(0, statement.commission)',
    },
    {
      desc: 'Returns the most recent date between Close Date and Payment Date.',
      formula: 'MAX(opportunity.closeDate, statementPeriod.paymentDate)',
    },
  ],
});