JSFiddle - React, Tailwind, and code Playground

by Turi S

JavaScript

function EvenPiece(points, color) {
    this.points = points;
    this.color = color;
 }
  
  
EvenPiece.prototype.getSpread = function() {
    return Math.max.apply(null, this.points.map(function(curr){
      return Math.max(
        Math.ceil(Math.abs(curr.x - 0.5)),
        Math.ceil(Math.abs(curr.y + 0.5))
      );
    }));
  };
  
  var O = new EvenPiece(
  	[{x:0, y:0}, {x:1, y:0}, {x:0, y:-1}, {x:1, y: -1}],
    "red"
  );
  
  alert(O.getSpread());