Dev Helpers
← Back

Compute a typed displacement vector

Compute a typed displacement vector using TypeScript.

Open this example in the interactive library

Source code

type Point = readonly [x: number, y: number];
const a: Point = [3, 4],
  b: Point = [7, 1];
console.log(
  ((from: Point, to: Point): Point => [to[0] - from[0], to[1] - from[1]])(a, b),
);

Sample output

[ 4, -3 ]