Skip to content

Commit eccfd80

Browse files
committed
Added the Javascript implementation from Doomsday
1 parent eb01cd6 commit eccfd80

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Unfortunately, sometimes the bug can be only reproduced in your project or in yo
2424

2525
1. Fork this repository.
2626

27-
2. check the table in README.md file weather the algorithm is added. If not add a new row with the name of algorithm and create a new folder with a name of the algorithm.
27+
2. Check the table in README.md file weather the algorithm is added. If not add a new row with the name of algorithm and create a new folder with a name of the algorithm.
2828

2929
3. Inside the folder create the folder for language you want to share. and add your code.
3030

3131
5. Commit
3232

33-
6. update the README.md. check the language you have used in the table. (check emoji is ``:+1:`` )
33+
6. Update the README.md. check the language you have used in the table. (check emoji is ``:+1:`` )
3434

3535
7. Commit, Push
3636

Doomsday/JavaScript/Doomsday.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/**
3+
* Determines the day of the week using Tomohiko Sakamoto's Algorithm
4+
* to calculate Day of Week based on Gregorian calendar.
5+
*/
6+
function dow(y, m, d) {
7+
let t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
8+
y -= (m < 3) ? 1 : 0;
9+
return Math.round(y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
10+
}
11+
12+
/**
13+
* Determines the day of the week using Tomohiko Sakamoto's Algorithm
14+
* to calculate Day of Week based on Gregorian calendar.
15+
*/
16+
function dowS(y, m, d) {
17+
switch (dow(y, m, d)) {
18+
case 0:
19+
return "Sunday";
20+
case 1:
21+
return "Monday";
22+
case 2:
23+
return "Tuesday";
24+
case 3:
25+
return "Wednesday";
26+
case 4:
27+
return "Thursday";
28+
case 5:
29+
return "Friday";
30+
case 6:
31+
return "Saturday";
32+
default:
33+
console.log("Unknown dow");
34+
}
35+
return null;
36+
}
37+
38+
console.log(dow(1886, 5, 1) + ": " + dowS(1886, 5, 1)); // 6: Saturday
39+
console.log(dow(1948, 12, 10) + ": " + dowS(1948, 12, 10)); // 5: Friday
40+
console.log(dow(2001, 1, 15) + ": " + dowS(2001, 1, 15)); // 1: Monday
41+
console.log(dow(2017, 10, 10) + ": " + dowS(2017, 10, 10)); // 2: Tuesday
42+
console.log(dow(2018, 1, 1) + ": " + dowS(2018, 1, 1)); // 1: Monday
43+
console.log(dow(2018, 2, 16) + ": " + dowS(2018, 2, 16)); // 5: Friday
44+
console.log(dow(2018, 5, 17) + ": " + dowS(2018, 5, 17)); // 4: Thursday

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BreadthFirstSearch | :+1: | :+1: | | :+1: | | | | |
1616
BubbleSort | :+1: | :+1: | :+1: | | :+1: | :+1: | | |
1717
DepthFirstSearch | | | | | :+1: | | | |
1818
Dijkstra's | :+1: | | | | :+1: | | | |
19-
Doomsday | :+1: | | | | | | | |
19+
Doomsday | :+1: | | | | | :+1: | | |
2020
ElevatorAlgorithm | :+1: | | | | | | | |
2121
Fibonacci | :+1: | :+1: | | :+1: | | | :+1: | |
2222
FisherYatesShuffle | :+1: | | | | :+1: | | | :+1: |

0 commit comments

Comments
 (0)