-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (35 loc) · 1.06 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
// ! 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, index) => {
let result = []
if (index !== undefined) {
for (let i = 0; i < dates.length; i++) {
result.push(Date.parse(dates[i]))
}
return result[index].toString().slice(0, -3)
} else {
for (let i = 0; i < dates.length; i++) {
result.push(Date.parse(dates[i]).toString().slice(0, -3))
}
return result.sort().join("-")
}
};
// ! 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,
};