From b9553463a3eed4e97d02c2ffdc3e69cf5fe610ac Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:14:57 +0800 Subject: [PATCH 1/5] Create ZellersCongruenceAlgorithm.js --- Maths/ZellersCongruenceAlgorithm.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Maths/ZellersCongruenceAlgorithm.js diff --git a/Maths/ZellersCongruenceAlgorithm.js b/Maths/ZellersCongruenceAlgorithm.js new file mode 100644 index 0000000000..3382173009 --- /dev/null +++ b/Maths/ZellersCongruenceAlgorithm.js @@ -0,0 +1,26 @@ +// Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence +export const zellersCongruenceAlgorithm = (day, month, year) => { + if (typeof day !== 'number' || typeof month !== 'number' || typeof year !== 'number') { + return new TypeError('Arguments are not all numbers.') + } + const q = day + let m = month + let y = year + if (month < 3) { + m += 12 + y -= 1 + } + day = + (q + Math.floor(26 * (m + 1) / 10) + (y % 100) + Math.floor((y % 100) / 4) + Math.floor(Math.floor(y / 100) / 4) + (5 * Math.floor(y / 100))) % + 7 + const days = [ + 'Saturday', + 'Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday' + ] + return days[day] +} From 525df1c430c3d019d0bc3196ac8fbf8fdbd5c9ae Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:21:52 +0800 Subject: [PATCH 2/5] Create ZellersCongruenceAlgorithm.test.js --- Maths/test/ZellersCongruenceAlgorithm.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Maths/test/ZellersCongruenceAlgorithm.test.js diff --git a/Maths/test/ZellersCongruenceAlgorithm.test.js b/Maths/test/ZellersCongruenceAlgorithm.test.js new file mode 100644 index 0000000000..9861fe1cad --- /dev/null +++ b/Maths/test/ZellersCongruenceAlgorithm.test.js @@ -0,0 +1,13 @@ +import { zellersCongruenceAlgorithm } from '../ZellersCongruenceAlgorithm' + +function testZeller (day, month, year, expected) { + test('Testing on ' + day + '/' + month + '/' + year, () => { + expect(zellersCongruenceAlgorithm(day, month, year)).toBe(expected) + }) +} + +expect(zellersCongruenceAlgorithm('this', 'should', 'error').toThrowError(new TypeError('Arguments are not all numbers.'))) +testZeller(25, 1, 2013, 'Friday') +testZeller(26, 1, 2013, 'Saturday') +testZeller(16, 4, 2022, 'Saturday') +testZeller(25, 4, 2022, 'Monday') From d007557d5080bc14dd0fd3cf61ff4d93a5ee22e7 Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:26:33 +0800 Subject: [PATCH 3/5] toThrowError not valid? --- Maths/test/ZellersCongruenceAlgorithm.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Maths/test/ZellersCongruenceAlgorithm.test.js b/Maths/test/ZellersCongruenceAlgorithm.test.js index 9861fe1cad..3a401a3e33 100644 --- a/Maths/test/ZellersCongruenceAlgorithm.test.js +++ b/Maths/test/ZellersCongruenceAlgorithm.test.js @@ -6,7 +6,11 @@ function testZeller (day, month, year, expected) { }) } -expect(zellersCongruenceAlgorithm('this', 'should', 'error').toThrowError(new TypeError('Arguments are not all numbers.'))) +test('Testing on this/should/throw', () => { + expect(() => { + zellersCongruenceAlgorithm('this', 'should', 'error') + }).toThrow(new TypeError('Arguments are not all numbers.')) +}) testZeller(25, 1, 2013, 'Friday') testZeller(26, 1, 2013, 'Saturday') testZeller(16, 4, 2022, 'Saturday') From 9dc30cd47f061b89a68097646522d09a71b2679c Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:30:25 +0800 Subject: [PATCH 4/5] Update ZellersCongruenceAlgorithm.test.js --- Maths/test/ZellersCongruenceAlgorithm.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/test/ZellersCongruenceAlgorithm.test.js b/Maths/test/ZellersCongruenceAlgorithm.test.js index 3a401a3e33..931a9348a0 100644 --- a/Maths/test/ZellersCongruenceAlgorithm.test.js +++ b/Maths/test/ZellersCongruenceAlgorithm.test.js @@ -9,7 +9,7 @@ function testZeller (day, month, year, expected) { test('Testing on this/should/throw', () => { expect(() => { zellersCongruenceAlgorithm('this', 'should', 'error') - }).toThrow(new TypeError('Arguments are not all numbers.')) + }).toThrowError(new TypeError('Arguments are not all numbers.')) }) testZeller(25, 1, 2013, 'Friday') testZeller(26, 1, 2013, 'Saturday') From 86c7eecf47e502124be4333a4417e5adcc64d5e5 Mon Sep 17 00:00:00 2001 From: merelymyself <88221256+merelymyself@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:34:19 +0800 Subject: [PATCH 5/5] throw, not return. --- Maths/ZellersCongruenceAlgorithm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/ZellersCongruenceAlgorithm.js b/Maths/ZellersCongruenceAlgorithm.js index 3382173009..728fc9cc16 100644 --- a/Maths/ZellersCongruenceAlgorithm.js +++ b/Maths/ZellersCongruenceAlgorithm.js @@ -1,7 +1,7 @@ // Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence export const zellersCongruenceAlgorithm = (day, month, year) => { if (typeof day !== 'number' || typeof month !== 'number' || typeof year !== 'number') { - return new TypeError('Arguments are not all numbers.') + throw new TypeError('Arguments are not all numbers.') } const q = day let m = month
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: