From afd0b45c1e6119b4a7fd940440d410ac0ac7487b Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 20 Jul 2023 18:28:54 -0300 Subject: [PATCH 1/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20improving?= =?UTF-8?q?=20and=20fixing=20some=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bit-Manipulation/IsPowerOfTwo.js | 5 +- Cellular-Automata/ConwaysGameOfLife.js | 11 ++-- Conversions/DateDayDifference.js | 2 +- Data-Structures/Graph/test/Graph2.test.js | 6 +- Data-Structures/Heap/MinPriorityQueue.js | 3 +- Data-Structures/Tree/Trie.js | 4 +- Dynamic-Programming/FindMonthCalendar.js | 3 +- Graphs/DijkstraSmallestPath.js | 67 ----------------------- Maths/MatrixMultiplication.js | 9 +-- Maths/MidpointIntegration.js | 4 +- Maths/SimpsonIntegration.js | 4 +- Sorts/SimplifiedWiggleSort.js | 23 ++++---- String/CheckRearrangePalindrome.js | 2 +- 13 files changed, 36 insertions(+), 107 deletions(-) diff --git a/Bit-Manipulation/IsPowerOfTwo.js b/Bit-Manipulation/IsPowerOfTwo.js index ec5bbcd170..ee466519ea 100644 --- a/Bit-Manipulation/IsPowerOfTwo.js +++ b/Bit-Manipulation/IsPowerOfTwo.js @@ -23,8 +23,5 @@ */ export const IsPowerOfTwo = (n) => { - if (n > 0 && (n & (n - 1)) === 0) { - return true - } - return false + return n > 0 && (n & (n - 1)) === 0 } diff --git a/Cellular-Automata/ConwaysGameOfLife.js b/Cellular-Automata/ConwaysGameOfLife.js index a4c6a9c901..6ce4474783 100644 --- a/Cellular-Automata/ConwaysGameOfLife.js +++ b/Cellular-Automata/ConwaysGameOfLife.js @@ -29,11 +29,12 @@ export function newGeneration (cells) { // Decide whether the cell is alive or dead const alive = cells[i][j] === 1 - if ((alive && neighbourCount >= 2 && neighbourCount <= 3) || (!alive && neighbourCount === 3)) { - nextGenerationRow.push(1) - } else { - nextGenerationRow.push(0) - } + + const cellIsAlive = + (alive && neighbourCount >= 2 && neighbourCount <= 3) || + (!alive && neighbourCount === 3) + + nextGenerationRow.push(cellIsAlive ? 1 : 0) } nextGeneration.push(nextGenerationRow) } diff --git a/Conversions/DateDayDifference.js b/Conversions/DateDayDifference.js index b9d45e6dc2..b2dfc45ebd 100644 --- a/Conversions/DateDayDifference.js +++ b/Conversions/DateDayDifference.js @@ -19,7 +19,7 @@ const DateToDay = (dd, mm, yyyy) => { const DateDayDifference = (date1, date2) => { // firstly, check that both input are string or not. - if (typeof date1 !== 'string' && typeof date2 !== 'string') { + if (typeof date1 !== 'string' || typeof date2 !== 'string') { return new TypeError('Argument is not a string.') } // extract the first date diff --git a/Data-Structures/Graph/test/Graph2.test.js b/Data-Structures/Graph/test/Graph2.test.js index 91473214ee..6d6816a8dc 100644 --- a/Data-Structures/Graph/test/Graph2.test.js +++ b/Data-Structures/Graph/test/Graph2.test.js @@ -5,9 +5,7 @@ describe('Test Graph2', () => { const graph = new Graph(vertices.length) // adding vertices - for (let i = 0; i < vertices.length; i++) { - graph.addVertex(vertices[i]) - } + vertices.forEach((vertice) => graph.addVertex(vertice)) // adding edges graph.addEdge('A', 'B') @@ -27,7 +25,7 @@ describe('Test Graph2', () => { expect(mockFn.mock.calls.length).toBe(vertices.length) // Collect adjacency lists from output (call args) - const adjListArr = mockFn.mock.calls.map(v => v[0]) + const adjListArr = mockFn.mock.calls.map((v) => v[0]) expect(adjListArr).toEqual([ 'A -> B D E ', diff --git a/Data-Structures/Heap/MinPriorityQueue.js b/Data-Structures/Heap/MinPriorityQueue.js index 5b543ce94f..1c420b6c71 100644 --- a/Data-Structures/Heap/MinPriorityQueue.js +++ b/Data-Structures/Heap/MinPriorityQueue.js @@ -47,8 +47,7 @@ class MinPriorityQueue { // returns boolean value whether the heap is full or not isFull () { - if (this.size === this.capacity) return true - return false + return this.size === this.capacity } // prints the heap diff --git a/Data-Structures/Tree/Trie.js b/Data-Structures/Tree/Trie.js index 90d7944f6b..69ae48a076 100644 --- a/Data-Structures/Tree/Trie.js +++ b/Data-Structures/Tree/Trie.js @@ -106,8 +106,8 @@ Trie.prototype.contains = function (word) { // find the node with given prefix const node = this.findPrefix(word) // No such word exists - if (node === null || node.count === 0) return false - return true + + return node !== null && node.count !== 0 } Trie.prototype.findOccurrences = function (word) { diff --git a/Dynamic-Programming/FindMonthCalendar.js b/Dynamic-Programming/FindMonthCalendar.js index 16d847c06f..964db02cd3 100644 --- a/Dynamic-Programming/FindMonthCalendar.js +++ b/Dynamic-Programming/FindMonthCalendar.js @@ -52,8 +52,7 @@ class Month { } isLeapYear (year) { - if (((year % 400) === 0) || (((year % 100) !== 0) && ((year % 4) === 0))) return true - return false + return ((year % 400) === 0) || (((year % 100) !== 0) && ((year % 4) === 0)) } isGreater (startDate, endDate) { diff --git a/Graphs/DijkstraSmallestPath.js b/Graphs/DijkstraSmallestPath.js index 81ee9767f3..10ada1f236 100644 --- a/Graphs/DijkstraSmallestPath.js +++ b/Graphs/DijkstraSmallestPath.js @@ -41,70 +41,3 @@ function solve (graph, s) { } export { solve } - -// // create graph -// const graph = {} - -// const layout = { -// R: ['2'], -// 2: ['3', '4'], -// 3: ['4', '6', '13'], -// 4: ['5', '8'], -// 5: ['7', '11'], -// 6: ['13', '15'], -// 7: ['10'], -// 8: ['11', '13'], -// 9: ['14'], -// 10: [], -// 11: ['12'], -// 12: [], -// 13: ['14'], -// 14: [], -// 15: [] -// } - -// // convert uni-directional to bi-directional graph -// let graph = { -// a: {e:1, b:1, g:3}, -// b: {a:1, c:1}, -// c: {b:1, d:1}, -// d: {c:1, e:1}, -// e: {d:1, a:1}, -// f: {g:1, h:1}, -// g: {a:3, f:1}, -// h: {f:1} -// }; - -// for (const id in layout) { -// if (!graph[id]) { graph[id] = {} } -// layout[id].forEach(function (aid) { -// graph[id][aid] = 1 -// if (!graph[aid]) { graph[aid] = {} } -// graph[aid][id] = 1 -// }) -// } - -// // choose start node -// const start = '10' -// // get all solutions -// const solutions = solve(graph, start) - -// // for s in solutions.. -// ' -> ' + s + ': [' + solutions[s].join(', ') + '] (dist:' + solutions[s].dist + ')' - -// From '10' to -// -> 2: [7, 5, 4, 2] (dist:4) -// -> 3: [7, 5, 4, 3] (dist:4) -// -> 4: [7, 5, 4] (dist:3) -// -> 5: [7, 5] (dist:2) -// -> 6: [7, 5, 4, 3, 6] (dist:5) -// -> 7: [7] (dist:1) -// -> 8: [7, 5, 4, 8] (dist:4) -// -> 9: [7, 5, 4, 3, 13, 14, 9] (dist:7) -// -> 10: [] (dist:0) -// -> 11: [7, 5, 11] (dist:3) -// -> 12: [7, 5, 11, 12] (dist:4) -// -> 13: [7, 5, 4, 3, 13] (dist:5) -// -> 14: [7, 5, 4, 3, 13, 14] (dist:6) -// -> 15: [7, 5, 4, 3, 6, 15] (dist:6) -// -> R: [7, 5, 4, 2, R] (dist:5) diff --git a/Maths/MatrixMultiplication.js b/Maths/MatrixMultiplication.js index 739b6b1988..bddb5b1ec4 100644 --- a/Maths/MatrixMultiplication.js +++ b/Maths/MatrixMultiplication.js @@ -20,12 +20,9 @@ const matrixCheck = (matrix) => { // tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vice versa. const twoMatricesCheck = (first, second) => { const [firstRowLength, secondRowLength, firstColLength, secondColLength] = [first.length, second.length, matrixCheck(first), matrixCheck(second)] - if (firstRowLength !== secondColLength || secondRowLength !== firstColLength) { - // These matrices do not have a common side - return false - } else { - return true - } + + // These matrices do not have a common side + return firstRowLength === secondColLength && secondRowLength === firstColLength } // returns an empty array that has the same number of rows as the left matrix being multiplied. diff --git a/Maths/MidpointIntegration.js b/Maths/MidpointIntegration.js index 175875a47e..5695f09f44 100644 --- a/Maths/MidpointIntegration.js +++ b/Maths/MidpointIntegration.js @@ -42,7 +42,9 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h temp = 0 - for (let i = 0; i < pointsArray.length; i++) temp += pointsArray[i] + pointsArray.forEach(point => { + temp += point + }) result *= temp diff --git a/Maths/SimpsonIntegration.js b/Maths/SimpsonIntegration.js index b9aa5ade17..16dd4fa036 100644 --- a/Maths/SimpsonIntegration.js +++ b/Maths/SimpsonIntegration.js @@ -55,7 +55,9 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h / 3 temp = 0 - for (let i = 0; i < pointsArray.length; i++) temp += pointsArray[i] + pointsArray.forEach(point => { + temp += point + }) result *= temp diff --git a/Sorts/SimplifiedWiggleSort.js b/Sorts/SimplifiedWiggleSort.js index ae0ea54e20..0acd6e1495 100644 --- a/Sorts/SimplifiedWiggleSort.js +++ b/Sorts/SimplifiedWiggleSort.js @@ -8,29 +8,30 @@ import { quickSelectSearch } from '../Search/QuickSelectSearch.js' export const simplifiedWiggleSort = function (arr) { + const arrSize = arr.length // find Median using QuickSelect - let median = quickSelectSearch(arr, Math.floor(arr.length / 2.0)) - median = median[Math.floor(arr.length / 2.0)] + let median = quickSelectSearch(arr, Math.floor(arrSize / 2.0)) + median = median[Math.floor(arrSize / 2.0)] - const sorted = new Array(arr.length) + const sorted = new Array(arrSize) let smallerThanMedianIndx = 0 - let greaterThanMedianIndx = arr.length - 1 - (arr.length % 2) + let greaterThanMedianIndx = arrSize - 1 - (arrSize % 2) - for (let i = 0; i < arr.length; i++) { - if (arr[i] > median) { - sorted[greaterThanMedianIndx] = arr[i] + arr.forEach(element => { + if (element > median) { + sorted[greaterThanMedianIndx] = element greaterThanMedianIndx -= 2 } else { - if (smallerThanMedianIndx < arr.length) { - sorted[smallerThanMedianIndx] = arr[i] + if (smallerThanMedianIndx < arrSize) { + sorted[smallerThanMedianIndx] = element smallerThanMedianIndx += 2 } else { - sorted[greaterThanMedianIndx] = arr[i] + sorted[greaterThanMedianIndx] = element greaterThanMedianIndx -= 2 } } - } + }) return sorted } diff --git a/String/CheckRearrangePalindrome.js b/String/CheckRearrangePalindrome.js index 2f0e698ef2..f8ea2ccb23 100644 --- a/String/CheckRearrangePalindrome.js +++ b/String/CheckRearrangePalindrome.js @@ -12,7 +12,7 @@ export const palindromeRearranging = (str) => { return 'Not a string' } // Check if is a empty string - if (str.length === 0) { + if (!str) { return 'Empty string' } From 63e277267226359b1c12553a958cdfa4942baf4f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:29:42 +0000 Subject: [PATCH 2/8] Updated Documentation in README.md --- DIRECTORY.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index ec2b8f5dad..4f1c033352 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,5 +1,6 @@ * **Backtracking** * [AllCombinationsOfSizeK](Backtracking/AllCombinationsOfSizeK.js) + * [generateParentheses](Backtracking/generateParentheses.js) * [GeneratePermutations](Backtracking/GeneratePermutations.js) * [KnightTour](Backtracking/KnightTour.js) * [NQueens](Backtracking/NQueens.js) @@ -18,12 +19,14 @@ * [Memoize](Cache/Memoize.js) * **Cellular-Automata** * [ConwaysGameOfLife](Cellular-Automata/ConwaysGameOfLife.js) + * [Elementary](Cellular-Automata/Elementary.js) * **Ciphers** * [AffineCipher](Ciphers/AffineCipher.js) * [Atbash](Ciphers/Atbash.js) * [CaesarCipher](Ciphers/CaesarCipher.js) * [KeyFinder](Ciphers/KeyFinder.js) * [KeywordShiftedAlphabet](Ciphers/KeywordShiftedAlphabet.js) + * [MorseCode](Ciphers/MorseCode.js) * [ROT13](Ciphers/ROT13.js) * [VigenereCipher](Ciphers/VigenereCipher.js) * [XORCipher](Ciphers/XORCipher.js) @@ -66,6 +69,7 @@ * [Graph2](Data-Structures/Graph/Graph2.js) * [Graph3](Data-Structures/Graph/Graph3.js) * **Heap** + * [KeyPriorityQueue](Data-Structures/Heap/KeyPriorityQueue.js) * [MaxHeap](Data-Structures/Heap/MaxHeap.js) * [MinHeap](Data-Structures/Heap/MinHeap.js) * [MinPriorityQueue](Data-Structures/Heap/MinPriorityQueue.js) @@ -112,7 +116,10 @@ * [Shuf](Dynamic-Programming/Shuf.js) * [SieveOfEratosthenes](Dynamic-Programming/SieveOfEratosthenes.js) * **Sliding-Window** + * [HouseRobber](Dynamic-Programming/Sliding-Window/HouseRobber.js) * [LongestSubstringWithoutRepeatingCharacters](Dynamic-Programming/Sliding-Window/LongestSubstringWithoutRepeatingCharacters.js) + * [MaxConsecutiveOnes](Dynamic-Programming/Sliding-Window/MaxConsecutiveOnes.js) + * [MaxConsecutiveOnesIII](Dynamic-Programming/Sliding-Window/MaxConsecutiveOnesIII.js) * [PermutationinString](Dynamic-Programming/Sliding-Window/PermutationinString.js) * [SudokuSolver](Dynamic-Programming/SudokuSolver.js) * [TrappingRainWater](Dynamic-Programming/TrappingRainWater.js) @@ -212,6 +219,7 @@ * [ModularBinaryExponentiationRecursive](Maths/ModularBinaryExponentiationRecursive.js) * [NumberOfDigits](Maths/NumberOfDigits.js) * [Palindrome](Maths/Palindrome.js) + * [ParityOutlier](Maths/ParityOutlier.js) * [PascalTriangle](Maths/PascalTriangle.js) * [PerfectCube](Maths/PerfectCube.js) * [PerfectNumber](Maths/PerfectNumber.js) @@ -365,7 +373,6 @@ * [Upper](String/Upper.js) * [ValidateCreditCard](String/ValidateCreditCard.js) * [ValidateEmail](String/ValidateEmail.js) - * [ValidateUrl](String/ValidateUrl.js) * [ZFunction](String/ZFunction.js) * **Timing-Functions** * [GetMonthDays](Timing-Functions/GetMonthDays.js) From 636a3f6e2d82ae1b3a580bdea94c8d45bdde49c5 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 20 Jul 2023 18:33:57 -0300 Subject: [PATCH 3/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20improving?= =?UTF-8?q?=20isLeapYear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Maths/LeapYear.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Maths/LeapYear.js b/Maths/LeapYear.js index bddcea7afc..4aa94024e6 100644 --- a/Maths/LeapYear.js +++ b/Maths/LeapYear.js @@ -14,9 +14,5 @@ * @returns {boolean} true if this is a leap year, false otherwise. */ export const isLeapYear = (year) => { - if (year % 400 === 0) return true - if (year % 100 === 0) return false - if (year % 4 === 0) return true - - return false + return ((year % 400) === 0) || (((year % 100) !== 0) && ((year % 4) === 0)) } From 36bca3d8cca37d4d3d2bcafbc6d4250ce68cb674 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 17 Aug 2023 16:48:21 -0300 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=90=9B=20chore:=20back=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sorts/SimplifiedWiggleSort.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Sorts/SimplifiedWiggleSort.js b/Sorts/SimplifiedWiggleSort.js index 0acd6e1495..ae0ea54e20 100644 --- a/Sorts/SimplifiedWiggleSort.js +++ b/Sorts/SimplifiedWiggleSort.js @@ -8,30 +8,29 @@ import { quickSelectSearch } from '../Search/QuickSelectSearch.js' export const simplifiedWiggleSort = function (arr) { - const arrSize = arr.length // find Median using QuickSelect - let median = quickSelectSearch(arr, Math.floor(arrSize / 2.0)) - median = median[Math.floor(arrSize / 2.0)] + let median = quickSelectSearch(arr, Math.floor(arr.length / 2.0)) + median = median[Math.floor(arr.length / 2.0)] - const sorted = new Array(arrSize) + const sorted = new Array(arr.length) let smallerThanMedianIndx = 0 - let greaterThanMedianIndx = arrSize - 1 - (arrSize % 2) + let greaterThanMedianIndx = arr.length - 1 - (arr.length % 2) - arr.forEach(element => { - if (element > median) { - sorted[greaterThanMedianIndx] = element + for (let i = 0; i < arr.length; i++) { + if (arr[i] > median) { + sorted[greaterThanMedianIndx] = arr[i] greaterThanMedianIndx -= 2 } else { - if (smallerThanMedianIndx < arrSize) { - sorted[smallerThanMedianIndx] = element + if (smallerThanMedianIndx < arr.length) { + sorted[smallerThanMedianIndx] = arr[i] smallerThanMedianIndx += 2 } else { - sorted[greaterThanMedianIndx] = element + sorted[greaterThanMedianIndx] = arr[i] greaterThanMedianIndx -= 2 } } - }) + } return sorted } From 8d2cbda47f34877d81a7892f84474fcaf3b49bfe Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 17 Aug 2023 16:55:16 -0300 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20using=20reduce=20inst?= =?UTF-8?q?ead=20forEach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Maths/MidpointIntegration.js | 5 +---- Maths/SimpsonIntegration.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Maths/MidpointIntegration.js b/Maths/MidpointIntegration.js index 5695f09f44..4f1f6aa514 100644 --- a/Maths/MidpointIntegration.js +++ b/Maths/MidpointIntegration.js @@ -41,10 +41,7 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h - temp = 0 - pointsArray.forEach(point => { - temp += point - }) + temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0); result *= temp diff --git a/Maths/SimpsonIntegration.js b/Maths/SimpsonIntegration.js index 16dd4fa036..e8ff59f03b 100644 --- a/Maths/SimpsonIntegration.js +++ b/Maths/SimpsonIntegration.js @@ -54,10 +54,7 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h / 3 - temp = 0 - pointsArray.forEach(point => { - temp += point - }) + temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0); result *= temp From feae7268199d4b0676fe7498ca1f7f97546aa178 Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 17 Aug 2023 18:02:08 -0300 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20using=20reduce=20inst?= =?UTF-8?q?ead=20forEach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Maths/MidpointIntegration.js | 2 +- Maths/SimpsonIntegration.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Maths/MidpointIntegration.js b/Maths/MidpointIntegration.js index 4f1f6aa514..8e3fa61eb2 100644 --- a/Maths/MidpointIntegration.js +++ b/Maths/MidpointIntegration.js @@ -41,7 +41,7 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h - temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0); + temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0) result *= temp diff --git a/Maths/SimpsonIntegration.js b/Maths/SimpsonIntegration.js index e8ff59f03b..5ec41a89f3 100644 --- a/Maths/SimpsonIntegration.js +++ b/Maths/SimpsonIntegration.js @@ -54,7 +54,7 @@ function integralEvaluation (N, a, b, func) { // Calculate the integral let result = h / 3 - temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0); + temp = pointsArray.reduce((acc, currValue) => acc + currValue, 0) result *= temp From 80e6ba5b878969abc79725916766f782e5f01dfe Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 17 Aug 2023 18:05:13 -0300 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20removing=20duplicated?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dynamic-Programming/FindMonthCalendar.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Dynamic-Programming/FindMonthCalendar.js b/Dynamic-Programming/FindMonthCalendar.js index 964db02cd3..a2de02e8cf 100644 --- a/Dynamic-Programming/FindMonthCalendar.js +++ b/Dynamic-Programming/FindMonthCalendar.js @@ -3,6 +3,7 @@ * And prints out the month's calendar. * It uses an epoch of 1/1/1900, Monday. */ +import { isLeapYear } from '../Maths/LeapYear.js' class Month { constructor () { @@ -51,10 +52,6 @@ class Month { return dateOb } - isLeapYear (year) { - return ((year % 400) === 0) || (((year % 100) !== 0) && ((year % 4) === 0)) - } - isGreater (startDate, endDate) { if (startDate.year > endDate.year) { return true @@ -78,16 +75,16 @@ class Month { } let diff = 0 while (startDate.year !== endDate.year) { - diff += (this.isLeapYear(startDate.year)) ? 366 : 365 + diff += (isLeapYear(startDate.year)) ? 366 : 365 startDate.year = startDate.year + 1 } while (startDate.month !== endDate.month) { if (startDate.month < endDate.month) { - if (this.isLeapYear(startDate.year)) diff += this.monthDaysLeap[startDate.month] + if (isLeapYear(startDate.year)) diff += this.monthDaysLeap[startDate.month] else diff += this.monthDays[startDate.month] startDate.month = startDate.month + 1 } else { - if (this.isLeapYear(startDate.year)) diff -= this.monthDaysLeap[startDate.month - 1] + if (isLeapYear(startDate.year)) diff -= this.monthDaysLeap[startDate.month - 1] else diff -= this.monthDays[startDate.month - 1] startDate.month = startDate.month - 1 } @@ -102,7 +99,7 @@ class Month { let Month2 = this.parseDate(date) day = (this.isGreater(Month2, this.epoch)) ? this.Days[difference] : this.BDays[difference] Month2 = this.parseDate(date) - if (this.isLeapYear(Month2.year)) this.printCal(this.monthDaysLeap[Month2.month], day) + if (isLeapYear(Month2.year)) this.printCal(this.monthDaysLeap[Month2.month], day) else this.printCal(this.monthDays[Month2.month], day) } } From defbdec32f7287751587ffc779bcadf5eeefa6ad Mon Sep 17 00:00:00 2001 From: CarlosZoft Date: Thu, 17 Aug 2023 18:08:59 -0300 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=90=9B=20chore:=20removing=20.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dynamic-Programming/FindMonthCalendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic-Programming/FindMonthCalendar.js b/Dynamic-Programming/FindMonthCalendar.js index a2de02e8cf..6070cb11db 100644 --- a/Dynamic-Programming/FindMonthCalendar.js +++ b/Dynamic-Programming/FindMonthCalendar.js @@ -3,7 +3,7 @@ * And prints out the month's calendar. * It uses an epoch of 1/1/1900, Monday. */ -import { isLeapYear } from '../Maths/LeapYear.js' +import { isLeapYear } from '../Maths/LeapYear' class Month { constructor () {