-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 1.09 KB
/
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
34
35
36
37
38
39
40
41
42
// ! JANGAN DIMODIFIKASI
const dates = [
"2019-01-02", // 1546387200 (epoch time, dalam detik)
"2022-05-06 00:00:00 UTC-2", // 1651802400 (epoch time, dalam detik)
"2021-03-04 07:00:00 UTC", // 1614841200 (epoch time, dalam detik)
"2021-04-05 00:00:00 UTC+2", // 1617573600 (epoch time, dalam detik)
"2020-02-03 UTC+7", // 1580662800 (epoch time, dalam detik)
];
// TODO: Buatlah fungsi createDate
const createDate = (dates, num) => {
const array = [];
for (let i = 0; i < dates.length; i++) {
const date = new Date(dates[i]).getTime() / 1000;
const dateString = date.toString();
array.push(dateString);
}
if (num === undefined) {
const sortDate = array.sort((a, b) => a - b);
return sortDate.join("-");
} else {
const sortDate = array.sort((a, b) => a + b);
return array[num];
}
};
// ! JANGAN DIMODIFIKASI
(() => {
// IIFE
// '1546387200-1580662800-1614841200-1617573600-1651802400' (dalam string)
console.log(createDate?.(dates));
// '1614841200' (dalam string)
console.log(createDate?.(dates, 2));
})();
module.exports = {
dates,
createDate,
};