/math/add
stdAdds two values.
Type signature
(a: number, b: number) => number
Examples
add(3, 5);
// ⇒ 8
Try in REPL
Questions
- How to add two values?
(a: number, b: number) => number
add(3, 5);
// ⇒ 8
Try in REPL
(xs?: number[]) => number
average([2, 4, 15]);
// ⇒ 7
Try in REPL
(x: number) => number
ceilToNearestPowerOfTwo(345);
// ⇒ 512
Try in REPL
(min: number, max: number) => ((x: number) => number)
clamp(0, 10)(5);
// ⇒ 5
Try in REPL
clamp(0, 10)(-5);
// ⇒ 0
Try in REPL
clamp(0, 10)(15);
// ⇒ 10
Try in REPL
(x: number) => number
clampNormal(0.5);
// ⇒ 0.5
Try in REPL
clampNormal(-0.5);
// ⇒ 0
Try in REPL
clampNormal(1.5);
// ⇒ 1
Try in REPL
(x: number) => number
clampPercentage(50);
// ⇒ 50
Try in REPL
clampPercentage(-50);
// ⇒ 0
Try in REPL
clampPercentage(150);
// ⇒ 100
Try in REPL
(a: number, b: number) => number
delta(-3, 5);
// ⇒ 8
Try in REPL
(width: number, height: number) => ((x: number, y: number) => boolean)
inRectangleRange(50, 100)(25, 50);
// ⇒ true
Try in REPL
inRectangleRange(50, 100)(-25, 50);
// ⇒ false
Try in REPL
(t: number) => ((a: number, b: number) => number)
lerp(0.5)(0, 10);
// ⇒ 5
Try in REPL
lerp(0)(0, 10);
// ⇒ 0
Try in REPL
lerp(1)(0, 10);
// ⇒ 10
Try in REPL
(f: (x: number) => number) => ((xs: number[]) => number)
maximumBy(({ age }) => age)([
{ age: 13 },
{ age: 20 },
{ age: 7 },
{ age: 18 },
]);
// ⇒ { age: 20 }
Try in REPL
(xs?: number[]) => number | undefined
median([-5, 3, 2, 29, 43]);
// ⇒ 3
Try in REPL
([a, b]: [number, number]) => [number, number]
(xs: number[]) => boolean
(x: number) => number
sign(3);
// ⇒ 1
Try in REPL
sign(-5);
// ⇒ 5
Try in REPL
sign(0);
// ⇒ 0
Try in REPL
sign(-0);
// ⇒ 0
Try in REPL
(xs: number[], origin?: number) => number
standardDeviation([
96, 81, 68, 79, 23, 13, 13, 59,
44, 86,
]);
// ⇒ (2 * Math.sqrt(10922 / 5)) / 3
Try in REPL
(a: number, b: number) => number
subtract(3, 5);
// ⇒ -2
Try in REPL