-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (28 loc) · 929 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
34
35
36
37
38
// Given a date, return the corresponding day of the week for that date.
// The input is given as three integers representing the day, month and year respectively.
// Return the answer as one of the following values { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }.
// Example 1:
// Input: day = 31, month = 8, year = 2019
// Output: "Saturday"
// Example 2:
// Input: day = 18, month = 7, year = 1999
// Output: "Sunday"
// Example 3:
// Input: day = 15, month = 8, year = 1993
// Output: "Sunday"
// Constraints:
// The given dates are valid dates between the years 1971 and 2100.
// Solution
const dayOfTheWeek = (day, month, year) => {
const weekday = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
const date = new Date(year, month - 1, day)
return weekday[date.getDay()];
};