From b7309f0018722801232f9de6219666e6ef69fd32 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Fri, 7 Oct 2022 20:36:47 +0530 Subject: [PATCH 01/13] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Added=20solution=20?= =?UTF-8?q?for=20ProjectEuler-007?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem007.js | 27 +++++++++++++++++++++++++++ Project-Euler/test/Problem007.test.js | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Project-Euler/Problem007.js create mode 100644 Project-Euler/test/Problem007.test.js diff --git a/Project-Euler/Problem007.js b/Project-Euler/Problem007.js new file mode 100644 index 0000000000..48f27d56c1 --- /dev/null +++ b/Project-Euler/Problem007.js @@ -0,0 +1,27 @@ +import { PrimeCheck } from '../Maths/PrimeCheck.js' + +/** + * Find nth Prime Number + * + * P.S.(Project Euler - 007): + * By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. + * What is the 10001st prime number? + * + * @param {Number} n + * @returns {Number} returns the nth prime number + */ +export const nthPrime = (n) => { + if (n < 1) { + return 'Invalid Input' + } + + let count = 0 + let inc = 2 + while (count < n) { + if (PrimeCheck(inc)) { + count++ + } + inc++ + } + return inc - 1 +} diff --git a/Project-Euler/test/Problem007.test.js b/Project-Euler/test/Problem007.test.js new file mode 100644 index 0000000000..e979e45728 --- /dev/null +++ b/Project-Euler/test/Problem007.test.js @@ -0,0 +1,17 @@ +import { nthPrime } from '../Problem007.js' + +describe('checking nth prime number', () => { + it('should be invalid input if number is negative', () => { + expect(nthPrime(-3)).toBe('Invalid Input') + }) + it('should be invalid input if number is 0', () => { + expect(nthPrime(0)).toBe('Invalid Input') + }) + test('if the number is greather than 0', () => { + expect(nthPrime(10)).toBe(29) + }) + // Project Euler Condition Check + test('if the number is 10001', () => { + expect(nthPrime(10001)).toBe(104743) + }) +}) From d3a3b331c7d964262f524c37afb767c87994b6c3 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Fri, 7 Oct 2022 20:45:06 +0530 Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Spelling=20mistake?= =?UTF-8?q?=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/test/Problem007.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project-Euler/test/Problem007.test.js b/Project-Euler/test/Problem007.test.js index e979e45728..6c48f1e786 100644 --- a/Project-Euler/test/Problem007.test.js +++ b/Project-Euler/test/Problem007.test.js @@ -7,7 +7,7 @@ describe('checking nth prime number', () => { it('should be invalid input if number is 0', () => { expect(nthPrime(0)).toBe('Invalid Input') }) - test('if the number is greather than 0', () => { + test('if the number is greater than 0', () => { expect(nthPrime(10)).toBe(29) }) // Project Euler Condition Check From e9b5a6a92174ff87a4d9b27cee8e596ad8fa76a3 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Fri, 7 Oct 2022 23:02:44 +0530 Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20changed=20varia?= =?UTF-8?q?ble=20name=20from=20`inc`=20to=20`candidateValue`=20and=20throw?= =?UTF-8?q?n=20error=20in=20case=20of=20invalid=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem007.js | 10 +++++----- Project-Euler/test/Problem007.test.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Project-Euler/Problem007.js b/Project-Euler/Problem007.js index 48f27d56c1..95e3f10562 100644 --- a/Project-Euler/Problem007.js +++ b/Project-Euler/Problem007.js @@ -12,16 +12,16 @@ import { PrimeCheck } from '../Maths/PrimeCheck.js' */ export const nthPrime = (n) => { if (n < 1) { - return 'Invalid Input' + throw new Error('Invalid Input') } let count = 0 - let inc = 2 + let candidateValue = 2 while (count < n) { - if (PrimeCheck(inc)) { + if (PrimeCheck(candidateValue)) { count++ } - inc++ + candidateValue++ } - return inc - 1 + return candidateValue - 1 } diff --git a/Project-Euler/test/Problem007.test.js b/Project-Euler/test/Problem007.test.js index 6c48f1e786..191d1e06af 100644 --- a/Project-Euler/test/Problem007.test.js +++ b/Project-Euler/test/Problem007.test.js @@ -2,10 +2,10 @@ import { nthPrime } from '../Problem007.js' describe('checking nth prime number', () => { it('should be invalid input if number is negative', () => { - expect(nthPrime(-3)).toBe('Invalid Input') + expect(() => nthPrime(-3)).toThrowError('Invalid Input') }) it('should be invalid input if number is 0', () => { - expect(nthPrime(0)).toBe('Invalid Input') + expect(() => nthPrime(0)).toThrowError('Invalid Input') }) test('if the number is greater than 0', () => { expect(nthPrime(10)).toBe(29) From e99c7225579aa6da265352daa5140c037281c311 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Fri, 7 Oct 2022 23:23:09 +0530 Subject: [PATCH 04/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Modified=20the?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem007.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project-Euler/Problem007.js b/Project-Euler/Problem007.js index 95e3f10562..009c1a896e 100644 --- a/Project-Euler/Problem007.js +++ b/Project-Euler/Problem007.js @@ -16,12 +16,12 @@ export const nthPrime = (n) => { } let count = 0 - let candidateValue = 2 + let candidateValue = 1 while (count < n) { + candidateValue++ if (PrimeCheck(candidateValue)) { count++ } - candidateValue++ } - return candidateValue - 1 + return candidateValue } From 0f9f1bab7decbea8a2fbfc06b4b8531a39d0d6e1 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Mon, 10 Oct 2022 19:50:16 +0530 Subject: [PATCH 05/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Added=20test=20?= =?UTF-8?q?case=20for=20ProjectEuler=20Problem001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem001.js | 4 +++- Project-Euler/test/Problem001.test.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Project-Euler/test/Problem001.test.js diff --git a/Project-Euler/Problem001.js b/Project-Euler/Problem001.js index 65a35e32a1..c47c10bd1c 100644 --- a/Project-Euler/Problem001.js +++ b/Project-Euler/Problem001.js @@ -5,9 +5,11 @@ Find the sum of all the multiples of 3 or 5 below the provided parameter value n */ const multiplesThreeAndFive = (num) => { + if (num < 1) throw new Error('No natural numbers exist below 1') + let total = 0 // total for calculating the sum - for (let i = 0; i < num; i++) { + for (let i = 1; i < num; i++) { if (i % 3 === 0 || i % 5 === 0) { total += i } diff --git a/Project-Euler/test/Problem001.test.js b/Project-Euler/test/Problem001.test.js new file mode 100644 index 0000000000..e6b5549a57 --- /dev/null +++ b/Project-Euler/test/Problem001.test.js @@ -0,0 +1,17 @@ +import { multiplesThreeAndFive } from '../Problem001.js' + +describe('Sum of multiples of 3 or 5', () => { + it('should throw error when number is negative number', () => { + expect(() => multiplesThreeAndFive(-24)).toThrowError('No natural numbers exist below 1') + }) + it('should throw error when number is 0', () => { + expect(() => multiplesThreeAndFive(0)).toThrowError('No natural numbers exist below 1') + }) + test('if the number is greater than 0', () => { + expect(multiplesThreeAndFive(10)).toBe(23) + }) + // Project Euler Condition Check + test('if the number is 1000', () => { + expect(multiplesThreeAndFive(1000)).toBe(233168) + }) +}) From 53e3938b0a29f0ee101b06c559d4f358cd7a0cd6 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Mon, 23 Oct 2023 00:32:56 +0530 Subject: [PATCH 06/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Added=20test=20?= =?UTF-8?q?cases=20for=20Project=20Euler=20Problem=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/test/Problem004.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Project-Euler/test/Problem004.test.js diff --git a/Project-Euler/test/Problem004.test.js b/Project-Euler/test/Problem004.test.js new file mode 100644 index 0000000000..cd6a55ac98 --- /dev/null +++ b/Project-Euler/test/Problem004.test.js @@ -0,0 +1,11 @@ +import { largestPalindromic } from '../Problem004.js' + +describe('Largest Palindromic Number', () => { + test('if digit is 2', () => { + expect(largestPalindromic(2)).toBe(9009) + }) + // Project Euler Condition Check + test('if digit is 3', () => { + expect(largestPalindromic(3)).toBe(906609) + }) +}) From 96224e7950ab7bde4799d8103523b779e523e58c Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Mon, 23 Oct 2023 00:34:58 +0530 Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20auto=20prettier?= =?UTF-8?q?=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bit-Manipulation/BinaryCountSetBits.js | 2 +- Maths/AutomorphicNumber.js | 2 +- Maths/test/AutomorphicNumber.test.js | 16 ++++----- Project-Euler/Problem006.js | 6 ++-- Recursive/test/BinaryEquivalent.test.js | 48 ++++++++++++------------- Search/InterpolationSearch.js | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Bit-Manipulation/BinaryCountSetBits.js b/Bit-Manipulation/BinaryCountSetBits.js index b879f3bd67..b959caf062 100644 --- a/Bit-Manipulation/BinaryCountSetBits.js +++ b/Bit-Manipulation/BinaryCountSetBits.js @@ -16,7 +16,7 @@ function BinaryCountSetBits(a) { let count = 0 while (a) { - a &= (a - 1) + a &= a - 1 count++ } diff --git a/Maths/AutomorphicNumber.js b/Maths/AutomorphicNumber.js index d1b6608316..ba008271fc 100644 --- a/Maths/AutomorphicNumber.js +++ b/Maths/AutomorphicNumber.js @@ -35,6 +35,6 @@ export const isAutomorphic = (n) => { n = Math.floor(n / 10) n_sq = Math.floor(n_sq / 10) } - + return true } diff --git a/Maths/test/AutomorphicNumber.test.js b/Maths/test/AutomorphicNumber.test.js index 19b963388c..57f40d27ee 100644 --- a/Maths/test/AutomorphicNumber.test.js +++ b/Maths/test/AutomorphicNumber.test.js @@ -9,19 +9,19 @@ describe('AutomorphicNumber', () => { }) test.each([ - { n: -3 , expected: false }, - { n: -25 , expected: false }, + { n: -3, expected: false }, + { n: -25, expected: false } ])('should return false when n is negetive', ({ n, expected }) => { expect(isAutomorphic(n)).toBe(false) }) test.each([ - { n: 7 , expected: false }, - { n: 83 , expected: false }, - { n: 0 , expected: true }, - { n: 1 , expected: true }, - { n: 376 , expected: true }, - { n: 90625 , expected: true }, + { n: 7, expected: false }, + { n: 83, expected: false }, + { n: 0, expected: true }, + { n: 1, expected: true }, + { n: 376, expected: true }, + { n: 90625, expected: true } ])('should return $expected when n is $n', ({ n, expected }) => { expect(isAutomorphic(n)).toBe(expected) }) diff --git a/Project-Euler/Problem006.js b/Project-Euler/Problem006.js index 474de2ae96..804b165558 100644 --- a/Project-Euler/Problem006.js +++ b/Project-Euler/Problem006.js @@ -1,8 +1,8 @@ // https://projecteuler.net/problem=6 export const squareDifference = (num = 100) => { - let sumOfSquares = (num)*(num+1)*(2*num+1)/6 - let sums = (num*(num+1))/2 - + let sumOfSquares = (num * (num + 1) * (2 * num + 1)) / 6 + let sums = (num * (num + 1)) / 2 + return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares } diff --git a/Recursive/test/BinaryEquivalent.test.js b/Recursive/test/BinaryEquivalent.test.js index b79a455eed..ddabb7d477 100644 --- a/Recursive/test/BinaryEquivalent.test.js +++ b/Recursive/test/BinaryEquivalent.test.js @@ -1,29 +1,29 @@ -import { binaryEquivalent } from "../BinaryEquivalent"; +import { binaryEquivalent } from '../BinaryEquivalent' const tests = [ - { - test: 2, - expectedValue: "10" - }, - { - test: 0, - expectedValue: "0" - }, - { - test: 543, - expectedValue: "1000011111" - }, - { - test: 4697621023, - expectedValue: "100011000000000000000001000011111" - } + { + test: 2, + expectedValue: '10' + }, + { + test: 0, + expectedValue: '0' + }, + { + test: 543, + expectedValue: '1000011111' + }, + { + test: 4697621023, + expectedValue: '100011000000000000000001000011111' + } ] -describe("Binary Equivalent", () => { - test.each(tests)( - "of $test should be $expectedValue", - ({test, expectedValue}) => { - expect(binaryEquivalent(test)).toBe(expectedValue); - } - ) +describe('Binary Equivalent', () => { + test.each(tests)( + 'of $test should be $expectedValue', + ({ test, expectedValue }) => { + expect(binaryEquivalent(test)).toBe(expectedValue) + } + ) }) diff --git a/Search/InterpolationSearch.js b/Search/InterpolationSearch.js index e6deae496f..93f3b78b0e 100644 --- a/Search/InterpolationSearch.js +++ b/Search/InterpolationSearch.js @@ -36,4 +36,4 @@ export function interpolationSearch(arr, key) { } return -1 -} \ No newline at end of file +} From ae8ac3a3530203f190ed960ada2f2b9fab562aec Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Wed, 25 Oct 2023 11:44:30 +0530 Subject: [PATCH 08/13] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Added=20solutuon=20?= =?UTF-8?q?and=20testcases=20for=20`Project=20Euler`=20problem=2019?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem019.js | 20 ++++++++++++++++++++ Project-Euler/test/Problem019.test.js | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Project-Euler/Problem019.js create mode 100644 Project-Euler/test/Problem019.test.js diff --git a/Project-Euler/Problem019.js b/Project-Euler/Problem019.js new file mode 100644 index 0000000000..2f6030be0c --- /dev/null +++ b/Project-Euler/Problem019.js @@ -0,0 +1,20 @@ +// https://projecteuler.net/problem=19 + +export const countSundays = (startYear = 1901, endYear = 2000) => { + + let n = 0, dayOfWeek = 2; + const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + + for (let year = startYear; year <= endYear; year++) { + + months[1] = 28 + (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0); + + for (const month of months) { + dayOfWeek += month % 7; + if (dayOfWeek % 7 === 0) { + n++; + } + } + } + return n; +} diff --git a/Project-Euler/test/Problem019.test.js b/Project-Euler/test/Problem019.test.js new file mode 100644 index 0000000000..6e1a050e53 --- /dev/null +++ b/Project-Euler/test/Problem019.test.js @@ -0,0 +1,11 @@ +import { countSundays } from '../Problem019.js' + +describe('Count Sundays', () => { + test('when start year is 1801 and end year is 1900', () => { + expect(countSundays(1801, 1900)).toBe(172) + }) + // Project Euler Condition Check + test('when start year is 1901 and end year is 2000', () => { + expect(countSundays()).toBe(171) + }) +}) From b996553796f7860436f85ff08aca01f2dd7cc9d7 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Wed, 25 Oct 2023 11:45:48 +0530 Subject: [PATCH 09/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Updated=20prett?= =?UTF-8?q?ier=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem019.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Project-Euler/Problem019.js b/Project-Euler/Problem019.js index 2f6030be0c..92e036702a 100644 --- a/Project-Euler/Problem019.js +++ b/Project-Euler/Problem019.js @@ -1,20 +1,19 @@ // https://projecteuler.net/problem=19 export const countSundays = (startYear = 1901, endYear = 2000) => { + let n = 0, + dayOfWeek = 2 + const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - let n = 0, dayOfWeek = 2; - const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + for (let year = startYear; year <= endYear; year++) { + months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) - for (let year = startYear; year <= endYear; year++) { - - months[1] = 28 + (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0); - - for (const month of months) { - dayOfWeek += month % 7; - if (dayOfWeek % 7 === 0) { - n++; - } - } + for (const month of months) { + dayOfWeek += month % 7 + if (dayOfWeek % 7 === 0) { + n++ + } } - return n; + } + return n } From 5d1f546a7d755490b9954e3fe279eb9ce2c3c0d7 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Wed, 25 Oct 2023 11:46:32 +0530 Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20indentation=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem019.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Project-Euler/Problem019.js b/Project-Euler/Problem019.js index 92e036702a..0b622a269a 100644 --- a/Project-Euler/Problem019.js +++ b/Project-Euler/Problem019.js @@ -1,19 +1,19 @@ // https://projecteuler.net/problem=19 export const countSundays = (startYear = 1901, endYear = 2000) => { - let n = 0, - dayOfWeek = 2 - const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + let n = 0; + let dayOfWeek = 2 + const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - for (let year = startYear; year <= endYear; year++) { - months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) + for (let year = startYear; year <= endYear; year++) { + months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) - for (const month of months) { - dayOfWeek += month % 7 - if (dayOfWeek % 7 === 0) { - n++ - } + for (const month of months) { + dayOfWeek += month % 7 + if (dayOfWeek % 7 === 0) { + n++ + } + } } - } - return n + return n } From 4962de41e176cb8d523cba7f642e8bbbe05b2b67 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Wed, 25 Oct 2023 11:47:12 +0530 Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Prettier=20modi?= =?UTF-8?q?fications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem019.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Project-Euler/Problem019.js b/Project-Euler/Problem019.js index 0b622a269a..79a3ad7c43 100644 --- a/Project-Euler/Problem019.js +++ b/Project-Euler/Problem019.js @@ -1,19 +1,19 @@ // https://projecteuler.net/problem=19 export const countSundays = (startYear = 1901, endYear = 2000) => { - let n = 0; - let dayOfWeek = 2 - const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + let n = 0 + let dayOfWeek = 2 + const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - for (let year = startYear; year <= endYear; year++) { - months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) + for (let year = startYear; year <= endYear; year++) { + months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) - for (const month of months) { - dayOfWeek += month % 7 - if (dayOfWeek % 7 === 0) { - n++ - } - } + for (const month of months) { + dayOfWeek += month % 7 + if (dayOfWeek % 7 === 0) { + n++ + } } - return n + } + return n } From 4d4555caf4324df73c6016116c5c060adc4e5917 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 25 Oct 2023 06:17:53 +0000 Subject: [PATCH 12/13] Updated Documentation in README.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index aea7b1548f..72b8a04415 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -166,6 +166,7 @@ * [Area](Maths/Area.js) * [ArithmeticGeometricMean](Maths/ArithmeticGeometricMean.js) * [ArmstrongNumber](Maths/ArmstrongNumber.js) + * [AutomorphicNumber](Maths/AutomorphicNumber.js) * [AverageMean](Maths/AverageMean.js) * [AverageMedian](Maths/AverageMedian.js) * [BinaryConvert](Maths/BinaryConvert.js) @@ -280,6 +281,7 @@ * [Problem016](Project-Euler/Problem016.js) * [Problem017](Project-Euler/Problem017.js) * [Problem018](Project-Euler/Problem018.js) + * [Problem019](Project-Euler/Problem019.js) * [Problem020](Project-Euler/Problem020.js) * [Problem021](Project-Euler/Problem021.js) * [Problem023](Project-Euler/Problem023.js) From c3b3bd51c5ef78160330ed3bc06670fe533329b0 Mon Sep 17 00:00:00 2001 From: Omkarnath Parida Date: Wed, 25 Oct 2023 11:47:12 +0530 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Prettier=20modi?= =?UTF-8?q?fications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project-Euler/Problem019.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Project-Euler/Problem019.js b/Project-Euler/Problem019.js index 0b622a269a..79a3ad7c43 100644 --- a/Project-Euler/Problem019.js +++ b/Project-Euler/Problem019.js @@ -1,19 +1,19 @@ // https://projecteuler.net/problem=19 export const countSundays = (startYear = 1901, endYear = 2000) => { - let n = 0; - let dayOfWeek = 2 - const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + let n = 0 + let dayOfWeek = 2 + const months = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - for (let year = startYear; year <= endYear; year++) { - months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) + for (let year = startYear; year <= endYear; year++) { + months[1] = 28 + ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) - for (const month of months) { - dayOfWeek += month % 7 - if (dayOfWeek % 7 === 0) { - n++ - } - } + for (const month of months) { + dayOfWeek += month % 7 + if (dayOfWeek % 7 === 0) { + n++ + } } - return n + } + return n }