Logo

Programming-Idioms

History of Idiom 179 > diff from v5 to v6

Edit summary for version 6 by 1.7.4:
[JS] This was an accidental duplicate so I enriched it

Version 5

2019-01-24, 13:21:04

Version 6

2019-01-24, 13:22:41

Idiom #179 Get center of a rectangle

Return the center c of the rectangle with coördinates(x1,y1,x2,y2)

Idiom #179 Get center of a rectangle

Return the center c of the rectangle with coördinates(x1,y1,x2,y2)

Code
const center = ({x1, y1, x2, y2}) => ({x: (x1 + x2) / 2, y: (y1 + y2) / 2})
Code
class Point {
  constructor (x, y) {
    this.x = x
    this.y = y
  }
}
const center = ({x1, y1, x2, y2}) => new Point ((x1 + x2) / 2, (y1 + y2) / 2)