Reduces over points, treating x and y separately.

// Sum x and y values
const total = Points.reduce(points, (p, acc) => {
return {x: p.x + acc.x, y: p.y + acc.y}
});
  • Parameters

    • pts: readonly Point[]

      Points to reduce

    • fn: ((p: Point, accumulated: Point) => Point)

      Reducer

    • Optionalinitial: Point

      Initial value, uses { x:0, y:0 } by default

    Returns Point