-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (29 loc) · 647 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @param {number} A
* @param {number} B
* @param {number} C
* @param {number} D
* @param {number} E
* @param {number} F
* @param {number} G
* @param {number} H
* @return {number}
*/
var computeArea = function(A, B, C, D, E, F, G, H) {
var width, height;
if (C <= E || G <= A || D <= F || H <= B)
width = height = 0;
else {
if (E > A) {
width = G < C ? G - E : C - E;
} else {
width = C < G ? C - A : G - A;
}
if (F > B) {
height = H < D ? H - F : D - F;
} else {
height = D < H ? D - B: H - B;
}
}
return (C - A) * (D - B) + (G - E) * (H - F) - width * height;
};