2차원 좌표 평면에 변이 축과 평행한 직사각형이 있습니다. 직사각형 네 꼭짓점의 좌표 [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]가 담겨있는 배열 dots가 매개변수로 주어질 때, 직사각형의 넓이를 return 하도록 solution 함수를 완성해보세요.
- dots의 길이 = 4
- dots의 원소의 길이 = 2
- -256 < dots[i]의 원소 < 256
- 잘못된 입력은 주어지지 않습니다.
dots result [[1, 1], [2, 1], [2, 2], [1, 2]] 1 [[-1, -1], [1, 1], [1, -1], [-1, 1]] 4
function solution(dots) {
const w1 = Math.max(...dots.map(w=>w[0]))
const w2 = Math.min(...dots.map(w=>w[0]))
const h1 = Math.max(...dots.map(h=>h[1]))
const h2 = Math.min(...dots.map(h=>h[1]))
return (w1-w2)*(h1-h2);
}