-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-26-nested-logic.js
38 lines (32 loc) · 1.15 KB
/
day-26-nested-logic.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
34
35
36
37
38
function processData(input) {
//Enter your code here
const [actual, due] = input.split('\n');
const [actualDate, actualMonth, actualYear] = actual.split(' ').map(Number);
const actualDateObj = new Date(actualYear, actualMonth, actualDate);
const [dueDate, dueMonth, dueYear] = due.split(' ').map(Number);
const dueDateObj = new Date(dueYear, dueMonth, dueDate);
let fine = null;
if (actualDateObj.valueOf() <= dueDateObj.valueOf()) {
fine = 0;
} else if (actualYear === dueYear) {
if (actualMonth === dueMonth) {
fine = Math.abs(actualDate - dueDate)*15;
} else {
// can't use actualDateObj.getMonth(), dates such as 5/31/year will produce 6 instead of 5
// console.log(actualDateObj.getMonth(), dueDateObj.getMonth());
fine = Math.abs(actualMonth - dueMonth)*500;
}
} else {
fine = 10000;
}
process.stdout.write(`${fine}`);
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});