A throwaway repository for checking Clockgrove Pendulum releases end to end. Nothing here is real work.
src/math.mjs exports add and multiply(a, b), which returns the product of a and b.
import { multiply } from "./src/math.mjs";
multiply(3, 4); // 12It also exports subtract(a, b), which returns a minus b.
import { subtract } from "./src/math.mjs";
subtract(10, 4); // 6It also exports clamp(value, min, max), which returns min when value < min, max when value > max, and value otherwise. It throws a RangeError when min > max.
import { clamp } from "./src/math.mjs";
clamp(42, 0, 10); // 10It also exports mean(values), which returns the arithmetic mean of an array of numbers. It throws a RangeError when values is empty.
import { mean } from "./src/math.mjs";
mean([2, 4, 6]); // 4It also exports sum(values), which returns the total of an array of numbers. It returns 0 when values is empty.
import { sum } from "./src/math.mjs";
sum([1, 2, 3]); // 6It also exports square(x), which returns x times x.
import { square } from "./src/math.mjs";
square(3); // 9It also exports median(values), which returns the middle value of the sorted numbers, or the mean of the two middle values when the count is even. It throws a RangeError when values is empty.
import { median } from "./src/math.mjs";
median([3, 1, 2]); // 2It also exports max(values), which returns the largest number in an array of numbers. It throws a RangeError when values is empty.
import { max } from "./src/math.mjs";
max([3, 9, 2]); // 9It also exports min(values), which returns the smallest number in an array. It throws a RangeError when values is empty.
import { min } from "./src/math.mjs";
min([3, 9, 2]); // 2It also exports product(values), which returns the product of an array of numbers. It returns 1 when values is empty.
import { product } from "./src/math.mjs";
product([2, 3, 4]); // 24It also exports abs(x), which returns x when it is zero or positive and -x when it is negative.
import { abs } from "./src/math.mjs";
abs(-5); // 5It also exports sign(x), which returns 1 when x is greater than zero, -1 when it is less than zero, and 0 when it is zero. For NaN or any input that is not a number it returns NaN, like Math.sign.
import { sign } from "./src/math.mjs";
sign(-3); // -1It also exports lerp(a, b, t), which returns a + (b - a) * t, the point t of the way from a to b.
import { lerp } from "./src/math.mjs";
lerp(0, 10, 0.5); // 5It also exports cube(x), which returns x * x * x.
import { cube } from "./src/math.mjs";
cube(3); // 27It also exports isEven(n), which returns true when n % 2 === 0 and false otherwise.
import { isEven } from "./src/math.mjs";
isEven(4); // trueIt also exports factorial(n), which returns n!, the product n * (n - 1) * ... * 1, and 1 when n is 0. It throws a RangeError when n is negative or not an integer.
import { factorial } from "./src/math.mjs";
factorial(5); // 120It also exports gcd(a, b), which returns the greatest common divisor of the integers a and b as a non-negative number. The sign of either argument does not matter, and gcd(0, 0) is 0.
import { gcd } from "./src/math.mjs";
gcd(12, 18); // 6It also exports lcm(a, b), which returns the least common multiple of the integers a and b as a non-negative number. The sign of either argument does not matter, and it returns 0 when either argument is 0. It throws a RangeError when a or b is not an integer.
import { lcm } from "./src/math.mjs";
lcm(4, 6); // 12