Skip to main content
The Deno 2 Release Candidate is here
Learn more
Latest
class MathUtil
import { MathUtil } from "https://deno.land/x/sptaki@1.2.0/utils/MathUtil.d.ts";

Methods

arrayAdd(values: number[], summand: number): number[]

Helper to add a constant to all array elements

arrayCumsum(values: number[]): number[]

Helper to create the cumulative sum of all array elements arrayCumsum([1, 2, 3, 4]) = [1, 3, 6, 10]

arrayProd(values: number[], factor: number): number[]

Helper to create the product of each element times factor

arraySum(values: number[]): number

Helper to create the sum of all array elements

interp1(
xp: number,
x: number[],
y: number[],
): number

Linear interpolation e.g. used to do a continuous integration for quest rewards which are defined for specific support centers of pmcLevel

mapToRange(
x: number,
minIn: number,
maxIn: number,
minOut: number,
maxOut: number,
): number

Map a value from an input range to an output range linearly

Example: a_min = 0; a_max=1; b_min = 1; b_max=3; MathUtil.mapToRange(0.5, a_min, a_max, b_min, b_max) // returns 2