-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 729 Bytes
/
index.js
File metadata and controls
27 lines (22 loc) · 729 Bytes
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
function countHours(year, holidays) {
let hours = holidays.reduce((acc, el) => {
let valuesForDate = el.split('/')
let date = new Date(year, +(valuesForDate[0]) - 1, +(valuesForDate[1]))
return date.getDay() === 0 || date.getDay() === 6
? acc + 0
: acc += 2
}, 0)
return hours
}
function countHoursAlt1(year, holidays) {
return holidays.map(holiday => {
let date = new Date(`${ year }/${ holiday }`)
return [ 1, 2, 3, 4, 5 ].includes(date.getDay())
}).reduce((count, extraHour) => count + extraHour) * 2
}
function countHoursALt2(year, holidays) {
return holidays
.filter(diaMes => new Date(diaMes + "/" + year).getDay() % 6)
.length * 2
}
module.exports = countHours