Options
All
  • Public
  • Public/Protected
  • All
Menu

External module @tomato-js/math

Index

Variables

Const add

add: any = curry((num1: number, num2: number) => {return Number(num1) + Number(num2);})

两值相加,相当于a+b,带curry

增加于v0.0.12

脚本举例

  import { add } from '@tomato-js/math'
  add(3,4);//7
  add(3)(4);//7
param

传入的值

param

传入的值

returns

结果值

Const divide

divide: any = curry((num1: number, num2: number) => {return Number(num1) / Number(num2);})

两值相除,相当于a/b,带curry

增加于v0.0.12

脚本举例

  import { divide } from '@tomato-js/math'
  divide(12,3);//4
  divide(12)(3);//4
param

传入的值

param

传入的值

returns

结果值

Const multiply

multiply: any = curry((num1: number, num2: number) => {return Number(num1) * Number(num2);})

两值相乘,相当于a*b,带curry

增加于v0.0.12

脚本举例

  import { multiply } from '@tomato-js/math'
  multiply(4,3);//12
  multiply(4)(3);//12
param

传入的值

param

传入的值

returns

结果值

Const subtract

subtract: any = curry((num1: number, num2: number) => {return Number(num1) - Number(num2);})

两值相减,相当于a-b,带curry

增加于v0.0.12

脚本举例

  import { subtract } from '@tomato-js/math'
  subtract(4,3);//1
  subtract(4)(3);//1
param

传入的值

param

传入的值

returns

结果值

Functions

average

  • average(...nums: number[]): number
  • 求平均值

    脚本举例

      import { average } from '@tomato-js/math'
      average(...[1,2,3]);//2
      average(1,2,3);//2

    Parameters

    • Rest ...nums: number[]

      一个个传入的值

    Returns number

    平均值

averageBy

  • averageBy(arr: ObjectType<number>[], fn: (value: ObjectType<number>, index: number, array: ObjectType<number>[]) => number): number
  • 求平均值

    脚本举例

      import { averageBy } from '@tomato-js/math'
      averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n);

    Parameters

    • arr: ObjectType<number>[]
    • fn: (value: ObjectType<number>, index: number, array: ObjectType<number>[]) => number
        • (value: ObjectType<number>, index: number, array: ObjectType<number>[]): number
        • Parameters

          • value: ObjectType<number>
          • index: number
          • array: ObjectType<number>[]

          Returns number

    Returns number

    平均值

sum

  • sum(...nums: number[]): number
  • 求和

    脚本举例

      import { sum } from '@tomato-js/math'
      average(...[1,2,3]);//6
      average(1,2,3);//6

    Parameters

    • Rest ...nums: number[]

      一个个传入的值

    Returns number

    总和

sumBy

  • sumBy(arr: ObjectType<number>[], fn: (value: ObjectType<number>, index: number, array: ObjectType<number>[]) => number): number
  • 求和

    脚本举例

      import { sumBy } from '@tomato-js/math'
      sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n);

    Parameters

    • arr: ObjectType<number>[]
    • fn: (value: ObjectType<number>, index: number, array: ObjectType<number>[]) => number
        • (value: ObjectType<number>, index: number, array: ObjectType<number>[]): number
        • Parameters

          • value: ObjectType<number>
          • index: number
          • array: ObjectType<number>[]

          Returns number

    Returns number

    总和

Generated using TypeDoc