typestar

Clamp and lerp in TypeScript

Clamp and linear interpolation, the two functions every animation needs.

function clamp(value: number, min: number, max: number): number {
  return Math.min(Math.max(value, min), max);
}

function lerp(a: number, b: number, t: number): number {
  return a + (b - a) * clamp(t, 0, 1);
}

Keywords and builtins used here

The run, in numbers

Lines
7
Characters to type
208
Tokens
73
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 46 seconds.

Type this snippet

Step 4 of 5 in Functions & tuples, step 19 of 23 in Types & annotations.

← Previous Next →