Skip to main content

Math Methods

average

Computes the average of the values

Since: 0.1.0

Arguments

ParamTypeDescription
valuenumber[]The values to calculate.

Returns

TypeDescription
numberReturns the average of values

Declaration

declare function average(values: number[]): number;

Examples

average([1, 2, 3]); // 2

between

Checks if n is between start and up to end

Since: 0.1.0

Arguments

ParamTypeDescription
numbernumberThe number to check.
startnumberThe start of the range.
endnumberThe end of the range.

Returns

TypeDescription
booleanReturns true if number is in the range, else false.

Declaration

declare function between(number: number, start: number, end: number): boolean;

Examples

between(3, 1, 5); // true
between(8, 1, 5); // false

clamp

Clamp number

Since: 0.1.0

Arguments

ParamTypeDescription
numbernumberThe number to clamp
lowernumberThe lower bound
uppernumberThe upper bound

Returns

TypeDescription
numberReturns the clamped number

Declaration

declare function clamp(number: number, lower: number, upper: number): number;

Examples

clamp(3, 1, 5); // 3
clamp(8, 1, 5); // 5

sum

Computes the sum of the values

Since: 0.1.0

Arguments

ParamTypeDescription
valuenumber[]The values to calculate.

Returns

TypeDescription
numberReturns the sum of values

Declaration

declare function sum(values: number[]): number;

Examples

sum([1, 2, 3]); // 6