From 7a70ed789cd78fd596c51fb39998c1d5c90f7d6b Mon Sep 17 00:00:00 2001 From: Dev <60340125+ayazshah2@users.noreply.github.com> Date: Mon, 4 Oct 2021 11:26:14 +0400 Subject: [PATCH 01/31] capitalize first letter --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a44b38c5..384c8f625 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md). ## Algorithm Explanation -see our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) +See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) From 028e098b63bbf8f5ed46eedbaa38d09c28202db4 Mon Sep 17 00:00:00 2001 From: Damien Chazoule Date: Mon, 4 Oct 2021 13:40:17 +0200 Subject: [PATCH 02/31] Feat: Added Memoize Func --- Cache/Memoize.js | 29 ++++++++++++++++++++++++++ Cache/__tests__/Memoize.test.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Cache/Memoize.js create mode 100644 Cache/__tests__/Memoize.test.js diff --git a/Cache/Memoize.js b/Cache/Memoize.js new file mode 100644 index 000000000..932b6187c --- /dev/null +++ b/Cache/Memoize.js @@ -0,0 +1,29 @@ +/** + * Memoize + * @param {Function} fn + * @returns + */ +export const memoize = (func) => { + // eslint-disable-next-line no-console + console.log(`Creating cache for function '${func.name}'`) + + const cache = {} + + return (...args) => { + const [arg] = args + + if (arg in cache) { + // eslint-disable-next-line no-console + console.log(`Reading cache with argument ${arg}`) + + return cache[arg] + } + + // eslint-disable-next-line no-console + console.log(`Updating cache with argument ${arg}`) + + const result = func(arg) + cache[arg] = result + return result + } +} diff --git a/Cache/__tests__/Memoize.test.js b/Cache/__tests__/Memoize.test.js new file mode 100644 index 000000000..74f3f5762 --- /dev/null +++ b/Cache/__tests__/Memoize.test.js @@ -0,0 +1,37 @@ +import { memoize } from '../Memoize' + +const fibonacci = (n) => { + if (n < 2) { + return n + } + + return fibonacci(n - 2) + fibonacci(n - 1) +} + +const factorial = (n) => { + if (n === 0) { + return 1 + } + + return n * factorial(n - 1) +} + +describe('memoize', () => { + it('expects the fibonacci function to use the cache on the second call', () => { + const memoFibonacci = memoize(fibonacci) + + expect(memoFibonacci(5)).toEqual(fibonacci(5)) + expect(memoFibonacci(5)).toEqual(5) + expect(memoFibonacci(10)).toEqual(fibonacci(10)) + expect(memoFibonacci(10)).toEqual(55) + }) + + it('expects the factorial function to use the cache on the second call', () => { + const memoFactorial = memoize(factorial) + + expect(memoFactorial(5)).toEqual(factorial(5)) + expect(memoFactorial(5)).toEqual(120) + expect(memoFactorial(10)).toEqual(factorial(10)) + expect(memoFactorial(10)).toEqual(3_628_800) + }) +}) From c8fd5353ba2c90d79a1b954c0f525baecc640a10 Mon Sep 17 00:00:00 2001 From: Damien Chazoule Date: Mon, 4 Oct 2021 14:15:21 +0200 Subject: [PATCH 03/31] Updating Memoize Unit Test --- Cache/__tests__/Memoize.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cache/__tests__/Memoize.test.js b/Cache/__tests__/Memoize.test.js index 74f3f5762..4d156ce34 100644 --- a/Cache/__tests__/Memoize.test.js +++ b/Cache/__tests__/Memoize.test.js @@ -16,7 +16,7 @@ const factorial = (n) => { return n * factorial(n - 1) } -describe('memoize', () => { +describe('Memoize', () => { it('expects the fibonacci function to use the cache on the second call', () => { const memoFibonacci = memoize(fibonacci) @@ -32,6 +32,6 @@ describe('memoize', () => { expect(memoFactorial(5)).toEqual(factorial(5)) expect(memoFactorial(5)).toEqual(120) expect(memoFactorial(10)).toEqual(factorial(10)) - expect(memoFactorial(10)).toEqual(3_628_800) + expect(memoFactorial(10)).toEqual(3628800) }) }) From 85f8154f0749b7ed247821886b3adb5cb63be564 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:28:55 -0400 Subject: [PATCH 04/31] Fix typos and update description to include a link --- Conversions/UpperCaseConversion.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Conversions/UpperCaseConversion.js b/Conversions/UpperCaseConversion.js index d3a033815..4bbd5f14f 100644 --- a/Conversions/UpperCaseConversion.js +++ b/Conversions/UpperCaseConversion.js @@ -1,26 +1,26 @@ /* - Explanation :- a user gives a String (it can be incomplete lower or - partial lower) and then the program would convert it into a - complete(all characters in upper case) upper case string. The - logic we have used in the following program is: All the lower case - characters (a-z) has ASCII value ranging from 97 to 122 and their - corresponding upper case characters (A-Z) have ASCII values 32 + Explanation :- A user gives a string (it can be incomplete lowercase or + partially in lowercase) and then the program converts it into a + completely (all characters in uppercase) uppercase string. The + logic we have used in the following program is: All the lowercase + characters (a-z) has [ASCII](https://en.wikipedia.org/wiki/ASCII) value ranging from 97 to 122 and their + corresponding uppercase characters (A-Z) have ASCII values 32 lesser than them. For example โ€˜aโ€˜ has an ASCII value of 97 and โ€˜Aโ€˜ has an ASCII value of 65 (97 - 32). The same applies to other characters. */ /** - * UpperCaseConversion takes any case-style string and converts it to the upper case-style string. - * @param {String} inputString any case style string - * @returns {String} upper case string + * UpperCaseConversion takes any case-style string and converts it to the uppercase-style string. + * @param {string} inputString Any case style string + * @returns {string} Uppercase string */ const UpperCaseConversion = (inputString) => { // Take a string and split it into characters. const newString = inputString.split('').map(char => { // Get a character code by the use charCodeAt method. const presentCharCode = char.charCodeAt() - // If the character code lies between 97 to 122 it means they are in the lower case so convert it. + // If the character code lies between 97 to 122, it means they are in the lowercase so convert it. if (presentCharCode >= 97 && presentCharCode <= 122) { // Convert the case by use of the above explanation. return String.fromCharCode(presentCharCode - 32) From a21264698e4186ddc50004015a8c9e97de92cbb2 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:30:17 -0400 Subject: [PATCH 05/31] Update export for Jest testing --- Conversions/UpperCaseConversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/UpperCaseConversion.js b/Conversions/UpperCaseConversion.js index 4bbd5f14f..34d3e0b6e 100644 --- a/Conversions/UpperCaseConversion.js +++ b/Conversions/UpperCaseConversion.js @@ -32,4 +32,4 @@ const UpperCaseConversion = (inputString) => { return newString.join('') } -module.exports = UpperCaseConversion +export { UpperCaseConversion } From a4bde8200d7111c7d3bade3d6b4930e1548411b5 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:30:49 -0400 Subject: [PATCH 06/31] Update capitalization style of function name to align with convention --- Conversions/UpperCaseConversion.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Conversions/UpperCaseConversion.js b/Conversions/UpperCaseConversion.js index 34d3e0b6e..fb5e810a6 100644 --- a/Conversions/UpperCaseConversion.js +++ b/Conversions/UpperCaseConversion.js @@ -11,11 +11,11 @@ */ /** - * UpperCaseConversion takes any case-style string and converts it to the uppercase-style string. + * upperCaseConversion takes any case-style string and converts it to the uppercase-style string. * @param {string} inputString Any case style string * @returns {string} Uppercase string */ -const UpperCaseConversion = (inputString) => { +const upperCaseConversion = (inputString) => { // Take a string and split it into characters. const newString = inputString.split('').map(char => { // Get a character code by the use charCodeAt method. @@ -32,4 +32,4 @@ const UpperCaseConversion = (inputString) => { return newString.join('') } -export { UpperCaseConversion } +export { upperCaseConversion } From 9aa890b17037704499f91c7c386204dcf31fce31 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:37:15 -0400 Subject: [PATCH 07/31] Add tests for UpperCaseConversion --- Conversions/test/UpperCaseConverstion.test.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Conversions/test/UpperCaseConverstion.test.js diff --git a/Conversions/test/UpperCaseConverstion.test.js b/Conversions/test/UpperCaseConverstion.test.js new file mode 100644 index 000000000..39b479dfb --- /dev/null +++ b/Conversions/test/UpperCaseConverstion.test.js @@ -0,0 +1,43 @@ +import { upperCaseConversion } from "../UpperCaseConversion"; + +describe(('Test the upperCaseConversion function'), () => { + it('should return an empty string when the input is an empty string', () => { + expect(upperCaseConversion('')).toEqual('') + }) + + it('should return an all-uppercase string when input is an all-uppercase string', () => { + expect(upperCaseConversion('ALLUPPERCASE')).toEqual('ALLUPPERCASE') + }) + + it('should return an all-uppercase string when input is an all-uppercase string with spaces', () => { + expect(upperCaseConversion('ALL UPPERCASE')).toEqual('ALL UPPERCASE') + }) + + it('should return an all-uppercase string when input is an all-uppercase string with punctuation', () => { + expect(upperCaseConversion('ALL UPPER-CASE!')).toEqual('ALL UPPER-CASE!') + }) + + it('should return an all-uppercase string when input is an all-lowercase string', () => { + expect(upperCaseConversion('lowercaseinput')).toEqual('LOWERCASEINPUT') + }) + + it('should return an all-uppercase string when input is an all-lowercase string with spaces', () => { + expect(upperCaseConversion('lowercase input')).toEqual('LOWERCASE INPUT') + }) + + it('should return an all-uppercase string when input is an all-lowercase string with punctuation', () => { + expect(upperCaseConversion('lower-case, input.')).toEqual('LOWER-CASE, INPUT.') + }) + + it('should return an all-uppercase string when input is an mixed-case string', () => { + expect(upperCaseConversion('mixeDCaSeINPuT')).toEqual('MIXEDCASEINPUT') + }) + + it('should return an all-uppercase string when input is an mixed-case string with spaces', () => { + expect(upperCaseConversion('mixeD CaSe INPuT')).toEqual('MIXED CASE INPUT') + }) + + it('should return an all-uppercase string when input is an mixed-case string with punctuation', () => { + expect(upperCaseConversion('mixeD-CaSe INPuT!')).toEqual('MIXED-CASE INPUT!') + }) +}) From 220e75d0466963a959813b7d41c53c3f0f256e29 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:44:28 -0400 Subject: [PATCH 08/31] Fix standardjs warning --- Conversions/test/UpperCaseConverstion.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/test/UpperCaseConverstion.test.js b/Conversions/test/UpperCaseConverstion.test.js index 39b479dfb..a78ec5b9c 100644 --- a/Conversions/test/UpperCaseConverstion.test.js +++ b/Conversions/test/UpperCaseConverstion.test.js @@ -1,4 +1,4 @@ -import { upperCaseConversion } from "../UpperCaseConversion"; +import { upperCaseConversion } from '../UpperCaseConversion' describe(('Test the upperCaseConversion function'), () => { it('should return an empty string when the input is an empty string', () => { From 90a59e6b60f5cec6e5e34c3b5884a51c4e02c736 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:52:10 -0400 Subject: [PATCH 09/31] Update function name casing to match convention --- Conversions/TitleCaseConversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 2db9620ea..85aea1c2a 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -7,7 +7,7 @@ * @param {String} inputString input string * @returns {String} */ -const TitleCaseConversion = (inputString) => { +const titleCaseConversion = (inputString) => { // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' From 4ea13dee13b8f8bcfe9e4bc5d977f9d01b6a2c60 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:52:30 -0400 Subject: [PATCH 10/31] Update export style for Jest testing --- Conversions/TitleCaseConversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 85aea1c2a..65994a9fc 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -39,4 +39,4 @@ const titleCaseConversion = (inputString) => { return stringCollections.join(' ') } -module.exports = TitleCaseConversion +export { titleCaseConversion } From 4ab047ddc54627df9853d1886abecc71d7b42a98 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:53:19 -0400 Subject: [PATCH 11/31] Fix typos and add ASCII link --- Conversions/TitleCaseConversion.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 65994a9fc..9013cc924 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -3,17 +3,17 @@ */ /** - * The TitleCaseConversion converts a string into a title case string. - * @param {String} inputString input string - * @returns {String} + * The titleCaseConversion function converts a string into a title case string. + * @param {string} inputString The input string which can have any types of letter casing. + * @returns {string} A string that is in title case. */ const titleCaseConversion = (inputString) => { // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' - // Get a character code by the use charCodeAt method. + // Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method. const firstCharCode = word[0].charCodeAt() - // If the character code lies between 97 to 122 it means they are in the lower case so convert it. + // If the ASCII character code lies between 97 to 122 it means they are in the lowercase so convert it. if (firstCharCode >= 97 && firstCharCode <= 122) { // Convert the case by use of the above explanation. firstChar += String.fromCharCode(firstCharCode - 32) @@ -22,9 +22,9 @@ const titleCaseConversion = (inputString) => { firstChar += word[0] } const newWordChar = word.slice(1).split('').map(char => { - // Get a character code by the use charCodeAt method. + // Get the ASCII character code by the use charCodeAt method. const presentCharCode = char.charCodeAt() - // If the character code lies between 65 to 90 it means they are in the upper case so convert it. + // If the ASCII character code lies between 65 to 90, it means they are in the uppercase so convert it. if (presentCharCode >= 65 && presentCharCode <= 90) { // Convert the case by use of the above explanation. return String.fromCharCode(presentCharCode + 32) @@ -32,10 +32,10 @@ const titleCaseConversion = (inputString) => { // Else return the characters without any modification. return char }) - // return the first converted character and remaining character string. + // Return the first converted character and remaining character string. return firstChar + newWordChar.join('') }) - // convert all words in a string and return it. + // Convert all words in a string and return it. return stringCollections.join(' ') } From 184814745ed4c75b66621356595db0907ad66845 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:56:32 -0400 Subject: [PATCH 12/31] Update description/documentation with explanation of title case, and simplifying assumptions this function makes --- Conversions/TitleCaseConversion.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 9013cc924..72ba26299 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -1,5 +1,8 @@ /* - Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl + Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl. + [Title case](https://en.wikipedia.org/wiki/Title_case) is a style where all words are capitalized. Officially, title case + does not capitalize some words, such as very short words like "a" or "is", but for the purposes of this function, a general approach + is taken where all words are capitalized regarless of length. */ /** From 654c824fdd63385a9476808d495533bfe8a233f3 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 12:21:34 -0400 Subject: [PATCH 13/31] Add check to handle empty string input. Could throw an error instead, but to be consistent with other case conversion functions in this collection, it returns an empty string when input is empty string. --- Conversions/TitleCaseConversion.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 72ba26299..44967d124 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -11,6 +11,7 @@ * @returns {string} A string that is in title case. */ const titleCaseConversion = (inputString) => { + if (inputString === '') return '' // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' From ced6c891a62064b0e787b95c28565ebacb5f9e2d Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 12:23:05 -0400 Subject: [PATCH 14/31] Add tests for titleCaseConversion function --- Conversions/test/TitleCaseConversion.test.js | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Conversions/test/TitleCaseConversion.test.js diff --git a/Conversions/test/TitleCaseConversion.test.js b/Conversions/test/TitleCaseConversion.test.js new file mode 100644 index 000000000..a4eaa2ecd --- /dev/null +++ b/Conversions/test/TitleCaseConversion.test.js @@ -0,0 +1,51 @@ +import { titleCaseConversion } from '../TitleCaseConversion' + +describe(('Tests for the titleCaseConversion function'), () => { + it('should return an empty string when the input is an empty string', () => { + expect(titleCaseConversion('')).toEqual('') + }) + + it('should return the input string when the input string is a title case string', () => { + expect(titleCaseConversion('A Proper Title Case String')).toEqual('A Proper Title Case String') + }) + + it('should return a title case string when input is an all-uppercase string', () => { + expect(titleCaseConversion('ALL UPPER CASE')).toEqual('All Upper Case') + }) + + it('should return a title case string when input is a title case string of with spaces', () => { + expect(titleCaseConversion('ALL UPPERCASE')).toEqual('All Uppercase') + }) + + it('should return a title case string when input is a title case string of with no spaces', () => { + expect(titleCaseConversion('ALLUPPERCASE')).toEqual('Alluppercase') + }) + + it('should return a title case string when input is a title case string with punctuation', () => { + expect(titleCaseConversion('All Title Case!')).toEqual('All Title Case!') + }) + + it('should return a title case string when input is an all-lowercase string with no spaces', () => { + expect(titleCaseConversion('lowercaseinput')).toEqual('Lowercaseinput') + }) + + it('should return a title case string when input is an all-lowercase string with spaces', () => { + expect(titleCaseConversion('lowercase input')).toEqual('Lowercase Input') + }) + + it('should return a title case string when input is an all-lowercase string with punctuation', () => { + expect(titleCaseConversion('lower, case, input.')).toEqual('Lower, Case, Input.') + }) + + it('should return a title case string when input is an mixed-case string', () => { + expect(titleCaseConversion('mixeD CaSe INPuT')).toEqual('Mixed Case Input') + }) + + it('should return a title case string when input is an mixed-case string with no spaces', () => { + expect(titleCaseConversion('mixeDCaSeINPuT')).toEqual('Mixedcaseinput') + }) + + it('should return a title case string when input is an mixed-case string with punctuation', () => { + expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual('Mixed, Case, Input!') + }) +}) From 8bce33d2659e101c79fd33e70caca66db6770dc0 Mon Sep 17 00:00:00 2001 From: Damien Chazoule Date: Tue, 5 Oct 2021 08:50:12 +0200 Subject: [PATCH 15/31] Moving '__tests__' To 'test' --- Cache/Memoize.js | 12 +++--------- Cache/{__tests__ => test}/Memoize.test.js | 0 2 files changed, 3 insertions(+), 9 deletions(-) rename Cache/{__tests__ => test}/Memoize.test.js (100%) diff --git a/Cache/Memoize.js b/Cache/Memoize.js index 932b6187c..36309cbb3 100644 --- a/Cache/Memoize.js +++ b/Cache/Memoize.js @@ -4,24 +4,18 @@ * @returns */ export const memoize = (func) => { - // eslint-disable-next-line no-console - console.log(`Creating cache for function '${func.name}'`) - + // Initializing new cache const cache = {} return (...args) => { const [arg] = args if (arg in cache) { - // eslint-disable-next-line no-console - console.log(`Reading cache with argument ${arg}`) - + // Reading cache by argument return cache[arg] } - // eslint-disable-next-line no-console - console.log(`Updating cache with argument ${arg}`) - + // Updating cache by argument const result = func(arg) cache[arg] = result return result diff --git a/Cache/__tests__/Memoize.test.js b/Cache/test/Memoize.test.js similarity index 100% rename from Cache/__tests__/Memoize.test.js rename to Cache/test/Memoize.test.js From 15892639476d8a629f2fc9a133d6989345d202dc Mon Sep 17 00:00:00 2001 From: Keshav Bohra Date: Tue, 5 Oct 2021 12:49:23 +0530 Subject: [PATCH 16/31] fixed some spellings --- Backtracking/SumOfSubset.js | 4 ++-- Bit-Manipulation/BinaryCountSetBits.js | 4 ++-- Ciphers/KeyFinder.js | 2 +- Conversions/DateDayDifference.js | 4 ++-- Conversions/DateToDay.js | 2 +- Conversions/RailwayTimeConversion.js | 2 +- Conversions/TitleCaseConversion.js | 2 +- Data-Structures/Linked-List/CycleDetection.js | 2 +- Data-Structures/Linked-List/RotateListRight.js | 2 +- Data-Structures/Tree/AVLTree.js | 6 +++--- Data-Structures/Tree/Trie.js | 6 +++--- Dynamic-Programming/KadaneAlgo.js | 2 +- Dynamic-Programming/SieveOfEratosthenes.js | 2 +- .../tests/LongestPalindromicSubsequence.test.js | 8 ++++---- Geometry/ConvexHullGraham.js | 2 +- Graphs/Dijkstra.js | 2 +- Graphs/NumberOfIslands.js | 4 ++-- Hashes/SHA1.js | 6 +++--- Hashes/SHA256.js | 8 ++++---- Linear-Algebra/src/la_lib.js | 2 +- Maths/BinaryExponentiationRecursive.js | 2 +- Maths/CheckKishnamurthyNumber.js | 6 +++--- Maths/DigitSum.js | 2 +- Maths/ModularBinaryExponentiationRecursive.js | 2 +- Maths/PiApproximationMonteCarlo.js | 2 +- Maths/SieveOfEratosthenes.js | 2 +- Maths/SumOfDigits.js | 2 +- Maths/test/Fibonacci.test.js | 10 +++++----- Project-Euler/Problem014.js | 6 +++--- Search/StringSearch.js | 2 +- Sorts/BucketSort.js | 8 ++++---- Sorts/IntroSort.js | 6 +++--- Sorts/QuickSortRecursive.js | 2 +- Sorts/TimSort.js | 2 +- String/AlternativeStringArrange.js | 12 ++++++------ String/CheckPalindrome.js | 2 +- String/LevenshteinDistance.js | 4 ++-- String/MaxWord.js | 8 ++++---- String/test/MaxWord.test.js | 4 ++-- String/test/PatternMatching.test.js | 2 +- Trees/BreadthFirstTreeTraversal.js | 2 +- 41 files changed, 80 insertions(+), 80 deletions(-) diff --git a/Backtracking/SumOfSubset.js b/Backtracking/SumOfSubset.js index 16573e5fa..567656995 100644 --- a/Backtracking/SumOfSubset.js +++ b/Backtracking/SumOfSubset.js @@ -4,7 +4,7 @@ * * Given an ordered set W of non-negative integers and a value K, * determine all possible subsets from the given set W whose sum - * of its elemets equals to the given value K. + * of its elements equals to the given value K. * * More info: https://www.geeksforgeeks.org/subset-sum-backtracking-4/ */ @@ -53,7 +53,7 @@ const sumOfSubset = (set, subset, setindex, sum, targetSum) => { targetSum ) - // Concat the recursive result with current result arary + // Concat the recursive result with current result array results = [...results, ...subsetResult] }) diff --git a/Bit-Manipulation/BinaryCountSetBits.js b/Bit-Manipulation/BinaryCountSetBits.js index bb16afe94..3fcb9d619 100644 --- a/Bit-Manipulation/BinaryCountSetBits.js +++ b/Bit-Manipulation/BinaryCountSetBits.js @@ -3,13 +3,13 @@ license: GPL-3.0 or later This script will find number of 1's - in binary representain of given number + in binary representation of given number */ function BinaryCountSetBits (a) { 'use strict' - // convert number into binary representation and return number of set bits in binary representaion + // convert number into binary representation and return number of set bits in binary representation return a.toString(2).split('1').length - 1 } diff --git a/Ciphers/KeyFinder.js b/Ciphers/KeyFinder.js index 8a66facc6..1a4059e33 100644 --- a/Ciphers/KeyFinder.js +++ b/Ciphers/KeyFinder.js @@ -48,7 +48,7 @@ function keyFinder (str) { // str is used to get the input of encrypted string // console.log( k + outStrElement + wordBank[i] );//debug // this part need to be optimize with the calculation of the number of occurrence of word's probabilities - // linked list will be used in the next stage of development to calculate the number of occurace of the key + // linked list will be used in the next stage of development to calculate the number of occurrence of the key if (wordBank[i] === outStrElement) { return k // return the key number if founded } diff --git a/Conversions/DateDayDifference.js b/Conversions/DateDayDifference.js index 43a3a9264..4cf900089 100644 --- a/Conversions/DateDayDifference.js +++ b/Conversions/DateDayDifference.js @@ -22,9 +22,9 @@ const DateDayDifference = (date1, date2) => { if (typeof date1 !== 'string' && typeof date2 !== 'string') { return new TypeError('Argument is not a string.') } - // extarct the first date + // extract the first date const [firstDateDay, firstDateMonth, firstDateYear] = date1.split('/').map((ele) => Number(ele)) - // extarct the second date + // extract the second date const [secondDateDay, secondDateMonth, secondDateYear] = date2.split('/').map((ele) => Number(ele)) // check the both data are valid or not. if (firstDateDay < 0 || firstDateDay > 31 || diff --git a/Conversions/DateToDay.js b/Conversions/DateToDay.js index ed65d1854..52d3be852 100644 --- a/Conversions/DateToDay.js +++ b/Conversions/DateToDay.js @@ -44,7 +44,7 @@ const DateToDay = (date) => { if (typeof date !== 'string') { return new TypeError('Argument is not a string.') } - // extarct the date + // extract the date const [day, month, year] = date.split('/').map((x) => Number(x)) // check the data are valid or not. if (day < 0 || day > 31 || month > 12 || month < 0) { diff --git a/Conversions/RailwayTimeConversion.js b/Conversions/RailwayTimeConversion.js index f3d30fdef..65f9836c3 100644 --- a/Conversions/RailwayTimeConversion.js +++ b/Conversions/RailwayTimeConversion.js @@ -5,7 +5,7 @@ want some changes in hour value. Input Formate -> 07:05:45PM - Output Fromate -> 19:05:45 + Output Formate -> 19:05:45 Problem & Explanation Source : https://www.mathsisfun.com/time.html */ diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 2db9620ea..d02e2eac5 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -8,7 +8,7 @@ * @returns {String} */ const TitleCaseConversion = (inputString) => { - // Extact all space seprated string. + // Extract all space separated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' // Get a character code by the use charCodeAt method. diff --git a/Data-Structures/Linked-List/CycleDetection.js b/Data-Structures/Linked-List/CycleDetection.js index 910fe2214..ba33cd0c4 100644 --- a/Data-Structures/Linked-List/CycleDetection.js +++ b/Data-Structures/Linked-List/CycleDetection.js @@ -11,7 +11,7 @@ function main () { Note: * While Solving the problem in given link below, don't use main() function. * Just use only the code inside main() function. - * The purpose of using main() function here is to aviod global variables. + * The purpose of using main() function here is to avoid global variables. Link for the Problem: https://leetcode.com/problems/linked-list-cycle/ */ diff --git a/Data-Structures/Linked-List/RotateListRight.js b/Data-Structures/Linked-List/RotateListRight.js index 8acc7c767..5fbdc913e 100644 --- a/Data-Structures/Linked-List/RotateListRight.js +++ b/Data-Structures/Linked-List/RotateListRight.js @@ -10,7 +10,7 @@ function main () { Note: * While Solving the problem in given link below, don't use main() function. * Just use only the code inside main() function. - * The purpose of using main() function here is to aviod global variables. + * The purpose of using main() function here is to avoid global variables. Link for the Problem: https://leetcode.com/problems/rotate-list/ */ diff --git a/Data-Structures/Tree/AVLTree.js b/Data-Structures/Tree/AVLTree.js index 0c72ce365..fc48f470f 100644 --- a/Data-Structures/Tree/AVLTree.js +++ b/Data-Structures/Tree/AVLTree.js @@ -37,7 +37,7 @@ let utils; */ const AVLTree = (function () { function _avl (comp) { - /** @public compartor function */ + /** @public comparator function */ this._comp = undefined if (comp !== undefined) { this._comp = comp @@ -119,7 +119,7 @@ const AVLTree = (function () { node._right = rightRotate(node._right) return leftRotate(node) // Right Left } - return leftRotate(node) // Rigth Right + return leftRotate(node) // Right Right } // implement avl tree insertion const insert = function (root, val, tree) { @@ -202,7 +202,7 @@ const AVLTree = (function () { return true } /** - * TO check is a particluar element exists or not + * TO check is a particular element exists or not * @param {any} _val * @returns {Boolean} exists or not */ diff --git a/Data-Structures/Tree/Trie.js b/Data-Structures/Tree/Trie.js index 1e00daf53..e72f3ce5b 100644 --- a/Data-Structures/Tree/Trie.js +++ b/Data-Structures/Tree/Trie.js @@ -14,7 +14,7 @@ function Trie () { this.root = new TrieNode(null, null) } -// Recursively finds the occurence of all words in a given node +// Recursively finds the occurrence of all words in a given node Trie.findAllWords = function (root, word, output) { if (root === null) return if (root.count > 0) { @@ -79,11 +79,11 @@ Trie.prototype.remove = function (word, count) { child = child.children[key] } - // Delete no of occurences specified + // Delete no of occurrences specified if (child.count >= count) child.count -= count else child.count = 0 - // If some occurences are left we dont delete it or else + // If some occurrences are left we dont delete it or else // if the object forms some other objects prefix we dont delete it // For checking an empty object // https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object diff --git a/Dynamic-Programming/KadaneAlgo.js b/Dynamic-Programming/KadaneAlgo.js index 14ac0b18e..1e275dd09 100644 --- a/Dynamic-Programming/KadaneAlgo.js +++ b/Dynamic-Programming/KadaneAlgo.js @@ -10,7 +10,7 @@ function KadaneAlgo (array) { } } return maxSum - // This function returns largest sum contigous sum in a array + // This function returns largest sum contiguous sum in a array } function main () { const myArray = [1, 2, 3, 4, -6] diff --git a/Dynamic-Programming/SieveOfEratosthenes.js b/Dynamic-Programming/SieveOfEratosthenes.js index 1e0a2e2b2..b6b71a195 100644 --- a/Dynamic-Programming/SieveOfEratosthenes.js +++ b/Dynamic-Programming/SieveOfEratosthenes.js @@ -2,7 +2,7 @@ function sieveOfEratosthenes (n) { /* * Calculates prime numbers till a number n * :param n: Number upto which to calculate primes - * :return: A boolean list contaning only primes + * :return: A boolean list containing only primes */ const primes = new Array(n + 1) primes.fill(true) // set all as true initially diff --git a/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js b/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js index d68b392e9..bf5267acb 100644 --- a/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js +++ b/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js @@ -1,19 +1,19 @@ import { longestPalindromeSubsequence } from '../LongestPalindromicSubsequence' describe('LongestPalindromicSubsequence', () => { - it('expects to return 1 as longest pallindromic subsequence', () => { + it('expects to return 1 as longest palindromic subsequence', () => { expect(longestPalindromeSubsequence('abcdefgh')).toBe(1) }) - it('expects to return 4 as longest pallindromic subsequence', () => { + it('expects to return 4 as longest palindromic subsequence', () => { expect(longestPalindromeSubsequence('bbbab')).toBe(4) }) - it('expects to return 2 as longest pallindromic subsequence', () => { + it('expects to return 2 as longest palindromic subsequence', () => { expect(longestPalindromeSubsequence('cbbd')).toBe(2) }) - it('expects to return 7 as longest pallindromic subsequence', () => { + it('expects to return 7 as longest palindromic subsequence', () => { expect(longestPalindromeSubsequence('racexyzcxar')).toBe(7) }) }) diff --git a/Geometry/ConvexHullGraham.js b/Geometry/ConvexHullGraham.js index 304166347..756121fb5 100644 --- a/Geometry/ConvexHullGraham.js +++ b/Geometry/ConvexHullGraham.js @@ -33,7 +33,7 @@ function convexHull (points) { points.sort(compare) const p1 = points[0]; const p2 = points[pointsLen - 1] - // Divide Hull in two halfs + // Divide Hull in two halves const upperPoints = []; const lowerPoints = [] upperPoints.push(p1) diff --git a/Graphs/Dijkstra.js b/Graphs/Dijkstra.js index 159b19ad0..41bacd71d 100644 --- a/Graphs/Dijkstra.js +++ b/Graphs/Dijkstra.js @@ -2,7 +2,7 @@ * Author: Samarth Jain * Dijkstra's Algorithm implementation in JavaScript * Dijkstra's Algorithm calculates the minimum distance between two nodes. - * It is used to find the shortes path. + * It is used to find the shortest path. * It uses graph data structure. */ diff --git a/Graphs/NumberOfIslands.js b/Graphs/NumberOfIslands.js index 1f8627fcd..51a447dd0 100644 --- a/Graphs/NumberOfIslands.js +++ b/Graphs/NumberOfIslands.js @@ -2,8 +2,8 @@ https://dev.to/rattanakchea/amazons-interview-question-count-island-21h6 Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. -two a dimensial grid map -each element is going to represent a peice of land +a two dimensional grid map +each element is going to represent a piece of land 1 is land, 0 is water output a number which is the number of islands diff --git a/Hashes/SHA1.js b/Hashes/SHA1.js index b257a4301..864ca392a 100644 --- a/Hashes/SHA1.js +++ b/Hashes/SHA1.js @@ -9,11 +9,11 @@ const CHAR_SIZE = 8 /** - * Adds padding to binary/hex string represention + * Adds padding to binary/hex string representation * - * @param {string} str - string represention (binary/hex) + * @param {string} str - string representation (binary/hex) * @param {int} bits - total number of bits wanted - * @return {string} - string represention padding with empty (0) bits + * @return {string} - string representation padding with empty (0) bits * * @example * pad("10011", 8); // "00010011" diff --git a/Hashes/SHA256.js b/Hashes/SHA256.js index 9820981b8..d47dfb03e 100644 --- a/Hashes/SHA256.js +++ b/Hashes/SHA256.js @@ -20,11 +20,11 @@ const K = [ ] /** - * Adds padding to binary/hex string represention + * Adds padding to binary/hex string representation * - * @param {string} str - string represention (binary/hex) + * @param {string} str - string representation (binary/hex) * @param {int} bits - total number of bits wanted - * @return {string} - string represention padding with empty (0) bits + * @return {string} - string representation padding with empty (0) bits * * @example * pad("10011", 8); // "00010011" @@ -56,7 +56,7 @@ function chunkify (str, size) { } /** - * Rotates string represention of bits to th left + * Rotates string representation of bits to th left * * @param {string} bits - string representation of bits * @param {int} turns - number of rotations to make diff --git a/Linear-Algebra/src/la_lib.js b/Linear-Algebra/src/la_lib.js index 41f99a307..72d8473e8 100644 --- a/Linear-Algebra/src/la_lib.js +++ b/Linear-Algebra/src/la_lib.js @@ -26,7 +26,7 @@ let LinearAlgebra; if (N === comps.length) { this.components = comps } else { - throw new Error('Vector: invalide size!') + throw new Error('Vector: invalid size!') } } } // end of constructor diff --git a/Maths/BinaryExponentiationRecursive.js b/Maths/BinaryExponentiationRecursive.js index 0830f2bc6..6ff1ecbb6 100644 --- a/Maths/BinaryExponentiationRecursive.js +++ b/Maths/BinaryExponentiationRecursive.js @@ -2,7 +2,7 @@ Modified from: https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exponentiation.py - Explaination: + Explanation: https://en.wikipedia.org/wiki/Exponentiation_by_squaring */ diff --git a/Maths/CheckKishnamurthyNumber.js b/Maths/CheckKishnamurthyNumber.js index bb283e68e..d030fff84 100644 --- a/Maths/CheckKishnamurthyNumber.js +++ b/Maths/CheckKishnamurthyNumber.js @@ -1,11 +1,11 @@ /* Problem statement and Explanation : https://www.geeksforgeeks.org/check-if-a-number-is-a-krishnamurthy-number-or-not-2/ - krishnamurthy number is a number the sum of the all fectorial of the all dights is equal to the number itself. + krishnamurthy number is a number the sum of the all factorial of the all dights is equal to the number itself. 145 => 1! + 4! + 5! = 1 + 24 + 120 = 145 */ -// factorail utility method. +// factorial utility method. const factorial = (n) => { let fact = 1 while (n !== 0) { @@ -18,7 +18,7 @@ const factorial = (n) => { /** * krishnamurthy number is a number the sum of the factorial of the all dights is equal to the number itself. * @param {Number} number a number for checking is krishnamurthy number or not. - * @returns return correspond boolean vlaue, if the number is krishnamurthy number return `true` else return `false`. + * @returns return correspond boolean value, if the number is krishnamurthy number return `true` else return `false`. * @example 145 => 1! + 4! + 5! = 1 + 24 + 120 = 145 */ const CheckKishnamurthyNumber = (number) => { diff --git a/Maths/DigitSum.js b/Maths/DigitSum.js index 792915d60..e4a93d5bb 100644 --- a/Maths/DigitSum.js +++ b/Maths/DigitSum.js @@ -4,7 +4,7 @@ const digitSum = (num) => { // sum will store sum of digits of a number let sum = 0 - // while will run untill num become 0 + // while will run until num become 0 while (num) { sum += num % 10 num = parseInt(num / 10) diff --git a/Maths/ModularBinaryExponentiationRecursive.js b/Maths/ModularBinaryExponentiationRecursive.js index b8374bd17..434215c35 100644 --- a/Maths/ModularBinaryExponentiationRecursive.js +++ b/Maths/ModularBinaryExponentiationRecursive.js @@ -2,7 +2,7 @@ Modified from: https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exp_mod.py - Explaination: + Explanation: https://en.wikipedia.org/wiki/Exponentiation_by_squaring */ diff --git a/Maths/PiApproximationMonteCarlo.js b/Maths/PiApproximationMonteCarlo.js index be7f754e4..08849b547 100644 --- a/Maths/PiApproximationMonteCarlo.js +++ b/Maths/PiApproximationMonteCarlo.js @@ -1,5 +1,5 @@ // Wikipedia: https://en.wikipedia.org/wiki/Monte_Carlo_method -// Video Explaination: https://www.youtube.com/watch?v=ELetCV_wX_c +// Video Explanation: https://www.youtube.com/watch?v=ELetCV_wX_c const piEstimation = (iterations = 100000) => { let circleCounter = 0 diff --git a/Maths/SieveOfEratosthenes.js b/Maths/SieveOfEratosthenes.js index 9c6b4b911..e6e77b267 100644 --- a/Maths/SieveOfEratosthenes.js +++ b/Maths/SieveOfEratosthenes.js @@ -2,7 +2,7 @@ const sieveOfEratosthenes = (n) => { /* * Calculates prime numbers till a number n * :param n: Number upto which to calculate primes - * :return: A boolean list contaning only primes + * :return: A boolean list containing only primes */ const primes = new Array(n + 1) primes.fill(true) // set all as true initially diff --git a/Maths/SumOfDigits.js b/Maths/SumOfDigits.js index 859ef378b..e076be7a5 100644 --- a/Maths/SumOfDigits.js +++ b/Maths/SumOfDigits.js @@ -17,7 +17,7 @@ function sumOfDigitsUsingString (number) { } /* - The input is divided by 10 in each iteraction, till the input is equal to 0 + The input is divided by 10 in each iteration, till the input is equal to 0 The sum of all the digits is returned (The res variable acts as a collector, taking the remainders on each iteration) */ function sumOfDigitsUsingLoop (number) { diff --git a/Maths/test/Fibonacci.test.js b/Maths/test/Fibonacci.test.js index 30b7ba696..bccd799be 100644 --- a/Maths/test/Fibonacci.test.js +++ b/Maths/test/Fibonacci.test.js @@ -6,20 +6,20 @@ import { FibonacciMatrixExpo } from '../Fibonacci' -describe('Fibonanci', () => { - it('should return an array of numbers for FibonnaciIterative', () => { +describe('Fibonacci', () => { + it('should return an array of numbers for FibonacciIterative', () => { expect(FibonacciIterative(5)).toEqual( expect.arrayContaining([1, 1, 2, 3, 5]) ) }) - it('should return an array of numbers for FibonnaciRecursive', () => { + it('should return an array of numbers for FibonacciRecursive', () => { expect(FibonacciRecursive(5)).toEqual( expect.arrayContaining([1, 1, 2, 3, 5]) ) }) - it('should return number for FibonnaciRecursiveDP', () => { + it('should return number for FibonacciRecursiveDP', () => { expect(FibonacciRecursiveDP(5)).toBe(5) }) @@ -29,7 +29,7 @@ describe('Fibonanci', () => { ) }) - it('should return number for FibonnaciMatrixExpo', () => { + it('should return number for FibonacciMatrixExpo', () => { expect(FibonacciMatrixExpo(0)).toBe(0) expect(FibonacciMatrixExpo(1)).toBe(1) expect(FibonacciMatrixExpo(2)).toBe(1) diff --git a/Project-Euler/Problem014.js b/Project-Euler/Problem014.js index 62a2974ec..0331837d0 100644 --- a/Project-Euler/Problem014.js +++ b/Project-Euler/Problem014.js @@ -33,12 +33,12 @@ const getCollatzSequenceLength = (num, seqLength) => { const findLongestCollatzSequence = () => { let startingPointForLargestSequence = 1 - let largestSequnceLength = 1 + let largestSequenceLength = 1 for (let i = 2; i < 1000000; i++) { const currentSequenceLength = getCollatzSequenceLength(i, 1) - if (currentSequenceLength > largestSequnceLength) { + if (currentSequenceLength > largestSequenceLength) { startingPointForLargestSequence = i - largestSequnceLength = currentSequenceLength + largestSequenceLength = currentSequenceLength } } return startingPointForLargestSequence diff --git a/Search/StringSearch.js b/Search/StringSearch.js index 3cd9c1e3e..614575107 100644 --- a/Search/StringSearch.js +++ b/Search/StringSearch.js @@ -15,7 +15,7 @@ function makeTable (str) { // case 1. the current character doesn't match the last character of the longest prefix while (maxPrefix > 0 && str.charAt(i) !== str.charAt(maxPrefix)) { // if that is the case, we have to backtrack, and try find a character that will be equal to the current character - // if we reach 0, then we couldn't find a chracter + // if we reach 0, then we couldn't find a character maxPrefix = table[maxPrefix - 1] } // case 2. The last character of the longest prefix matches the current character in `str` diff --git a/Sorts/BucketSort.js b/Sorts/BucketSort.js index 9423c4c10..f05eacd76 100644 --- a/Sorts/BucketSort.js +++ b/Sorts/BucketSort.js @@ -54,11 +54,11 @@ function bucketSort (list, size) { } // Testing -const arrOrignal = [5, 6, 7, 8, 1, 2, 12, 14] -// > bucketSort(arrOrignal) +const arrOriginal = [5, 6, 7, 8, 1, 2, 12, 14] +// > bucketSort(arrOriginal) // [1, 2, 5, 6, 7, 8, 12, 14] // Array before Sort -console.log(arrOrignal) -const arrSorted = bucketSort(arrOrignal) +console.log(arrOriginal) +const arrSorted = bucketSort(arrOriginal) // Array after sort console.log(arrSorted) diff --git a/Sorts/IntroSort.js b/Sorts/IntroSort.js index 57edb4e8d..01d3c449d 100644 --- a/Sorts/IntroSort.js +++ b/Sorts/IntroSort.js @@ -1,7 +1,7 @@ /** * @function Intosort (As implemented in STD C++ Lib) * The function performs introsort which is used in - * C++ Standard LIbrary, the implemntation is inspired from] + * C++ Standard LIbrary, the implementation is inspired from] * library routine itself. * ALGORITHM: * 1) It performs quicksort on array until the recursion depth @@ -111,7 +111,7 @@ function introsort (array, compare) { */ quickSort(0, len, maxDepth) /** - * A final checlk call to insertion sort + * A final check call to insertion sort * on sorted array */ insertionSort(0, len) @@ -140,7 +140,7 @@ function introsort (array, compare) { } /** * @function Helper function to quicksort - * @param {Number} start the start of array segment to partitiion + * @param {Number} start the start of array segment to partition * @param {Number} last one more than last index of the array segment * @param {Number} pivot the index of pivot to be used * @returns {Number} the index of pivot after partition diff --git a/Sorts/QuickSortRecursive.js b/Sorts/QuickSortRecursive.js index 1ab3f4a8e..fe0cfae84 100644 --- a/Sorts/QuickSortRecursive.js +++ b/Sorts/QuickSortRecursive.js @@ -37,7 +37,7 @@ const quickSort = (inputList, low, high) => { /** * Partition In Place method. - * @param {number[]} partitionList list for partiting. + * @param {number[]} partitionList list for partitioning. * @param {number} low lower index for partition. * @param {number} high higher index for partition. * @returns {number} `pIndex` pivot index value. diff --git a/Sorts/TimSort.js b/Sorts/TimSort.js index 04c209f0f..07556404b 100644 --- a/Sorts/TimSort.js +++ b/Sorts/TimSort.js @@ -30,7 +30,7 @@ const Timsort = (array) => { /** * @function performs insertion sort on the partition * @param {Array} array array to be sorted - * @param {Number} left left index of partiton + * @param {Number} left left index of partition * @param {Number} right right index of partition */ diff --git a/String/AlternativeStringArrange.js b/String/AlternativeStringArrange.js index 6ff151f7d..9b722a1f9 100644 --- a/String/AlternativeStringArrange.js +++ b/String/AlternativeStringArrange.js @@ -14,24 +14,24 @@ const AlternativeStringArrange = (str1, str2) => { return 'Not string(s)' } - // output string vlaue. + // output string value. let outStr = '' // get first string length. const firstStringLength = str1.length // get second string length. const secondStringLength = str2.length - // absolute length for oparetion. - const absLenght = firstStringLength > secondStringLength ? firstStringLength : secondStringLength + // absolute length for operation. + const absLength = firstStringLength > secondStringLength ? firstStringLength : secondStringLength // Iterate the character count until the absolute count is reached. - for (let charCount = 0; charCount < absLenght; charCount++) { - // If firstStringLength is lesser than the charCount it means they are able to re-arange. + for (let charCount = 0; charCount < absLength; charCount++) { + // If firstStringLength is lesser than the charCount it means they are able to re-arrange. if (charCount < firstStringLength) { outStr += str1[charCount] } - // If secondStringLength is lesser than the charCount it means they are able to re-arange. + // If secondStringLength is lesser than the charCount it means they are able to re-arrange. if (charCount < secondStringLength) { outStr += str2[charCount] } diff --git a/String/CheckPalindrome.js b/String/CheckPalindrome.js index cca2620a6..a717ccd5f 100644 --- a/String/CheckPalindrome.js +++ b/String/CheckPalindrome.js @@ -8,7 +8,7 @@ const checkPalindrome = (str) => { if (str.length === 0) { return 'Empty string' } - // Reverse only works with array, thus conevert the string to array, reverse it and convert back to string + // Reverse only works with array, thus convert the string to array, reverse it and convert back to string // return as palindrome if the reversed string is equal to the input string const reversed = [...str].reverse().join('') return str === reversed ? 'Palindrome' : 'Not a Palindrome' diff --git a/String/LevenshteinDistance.js b/String/LevenshteinDistance.js index acb09a529..428e71265 100644 --- a/String/LevenshteinDistance.js +++ b/String/LevenshteinDistance.js @@ -15,12 +15,12 @@ const levenshteinDistance = (a, b) => { .fill(null) .map(() => Array(a.length + 1).fill(null)) - // Initialising first column: + // Initializing first column: for (let i = 0; i <= a.length; i += 1) { distanceMatrix[0][i] = i } - // Initialising first row: + // Initializing first row: for (let j = 0; j <= b.length; j += 1) { distanceMatrix[j][0] = j } diff --git a/String/MaxWord.js b/String/MaxWord.js index c3ac637ea..78199e3e9 100644 --- a/String/MaxWord.js +++ b/String/MaxWord.js @@ -1,15 +1,15 @@ -// Given a sentence, return the most occuring word +// Given a sentence, return the most occurring word /** - * @param {string} sentence - the sentence you want to find the most occuring word - * @returns {string} - the most occuring word + * @param {string} sentence - the sentence you want to find the most occurring word + * @returns {string} - the most occurring word * * @example * - maxWord('lala lili lala'); // lala */ const maxWord = (sentence = '') => { if (typeof sentence !== 'string') { - throw new TypeError('the param sould be string') + throw new TypeError('the param should be string') } if (!sentence) { diff --git a/String/test/MaxWord.test.js b/String/test/MaxWord.test.js index 8a5852ad6..417f1232d 100644 --- a/String/test/MaxWord.test.js +++ b/String/test/MaxWord.test.js @@ -6,7 +6,7 @@ describe('Testing the maxWord function', () => { }) it('get the max word', () => { const string = 'ba ba ba ba banana' - const mostOccuringWord = maxWord(string) - expect(mostOccuringWord).toBe('ba') + const mostOccurringWord = maxWord(string) + expect(mostOccurringWord).toBe('ba') }) }) diff --git a/String/test/PatternMatching.test.js b/String/test/PatternMatching.test.js index d0eab80b6..aff4e70d8 100644 --- a/String/test/PatternMatching.test.js +++ b/String/test/PatternMatching.test.js @@ -18,7 +18,7 @@ describe('checkIfPatternExists', () => { const SUT = checkIfPatternExists(text, pattern) expect(SUT).toBe(undefined) }) - it('expects to throw an error message when given inpuut is not a string', () => { + it('expects to throw an error message when given input is not a string', () => { const text = 123444456 const pattern = 123 expect(() => checkIfPatternExists(text, pattern)).toThrow( diff --git a/Trees/BreadthFirstTreeTraversal.js b/Trees/BreadthFirstTreeTraversal.js index f81cf24e6..b9195144d 100644 --- a/Trees/BreadthFirstTreeTraversal.js +++ b/Trees/BreadthFirstTreeTraversal.js @@ -25,7 +25,7 @@ class BinaryTree { return this.traversal.toLocaleString() } - // Compputing the height of the tree + // Computing the height of the tree getHeight (node) { if (node == null) { return 0 From 14034e29fe6c8bab1f6665887ab603f7c76ec76a Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Tue, 5 Oct 2021 12:51:04 +0530 Subject: [PATCH 17/31] chore: add punctuation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 384c8f625..3a841ce4e 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md). ## Algorithm Explanation -See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) +See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki). From 1c22f65ce72036469ab99c2d397e3b2f22f558fb Mon Sep 17 00:00:00 2001 From: Keshav Bohra Date: Tue, 5 Oct 2021 12:53:38 +0530 Subject: [PATCH 18/31] fixed the issue in Trie file and typo in sudoku --- Data-Structures/Tree/Trie.js | 2 +- Dynamic-Programming/SudokuSolver.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Data-Structures/Tree/Trie.js b/Data-Structures/Tree/Trie.js index 1e00daf53..61b4f03c1 100644 --- a/Data-Structures/Tree/Trie.js +++ b/Data-Structures/Tree/Trie.js @@ -87,7 +87,7 @@ Trie.prototype.remove = function (word, count) { // if the object forms some other objects prefix we dont delete it // For checking an empty object // https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object - if (child.count <= 0 && (Object.keys(child.children).length && child.childre.constructor === Object)) { + if (child.count <= 0 && (Object.keys(child.children).length && child.children.constructor === Object)) { child.parent.children[child.key] = undefined } } diff --git a/Dynamic-Programming/SudokuSolver.js b/Dynamic-Programming/SudokuSolver.js index bbba70e7b..23e913536 100644 --- a/Dynamic-Programming/SudokuSolver.js +++ b/Dynamic-Programming/SudokuSolver.js @@ -21,14 +21,14 @@ const isValid = (board, row, col, k) => { return true } -const sodokoSolver = (data) => { +const sudokuSolver = (data) => { for (let i = 0; i < 9; i++) { for (let j = 0; j < 9; j++) { if (data[i][j] === '.') { for (let k = 1; k <= 9; k++) { if (isValid(data, i, j, k)) { data[i][j] = `${k}` - if (sodokoSolver(data)) { + if (sudokuSolver(data)) { return true } else { data[i][j] = '.' @@ -44,7 +44,7 @@ const sodokoSolver = (data) => { // testing (() => { - if (sodokoSolver(_board)) { + if (sudokuSolver(_board)) { console.log(_board) } })() From 82ad8c8ad4b6779ac27ec250de3773d418c4e599 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 5 Oct 2021 08:15:04 +0000 Subject: [PATCH 19/31] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 6ae9a6d30..26ee705cb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -56,6 +56,7 @@ * test * [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js) * [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js) + * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/TitleCaseConversion.test.js) * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js) * [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js) From 0589fc19e0d18b43f65b315d7b99976503594df6 Mon Sep 17 00:00:00 2001 From: Damien Chazoule Date: Tue, 5 Oct 2021 10:37:14 +0200 Subject: [PATCH 20/31] Added comments about memoization --- Cache/Memoize.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Cache/Memoize.js b/Cache/Memoize.js index 36309cbb3..9bd998fda 100644 --- a/Cache/Memoize.js +++ b/Cache/Memoize.js @@ -1,21 +1,40 @@ /** * Memoize - * @param {Function} fn - * @returns + * + * From [Wikipedia](https://en.wikipedia.org/wiki/Memoization), + * memoization is an optimization technique + * used primarily to speed up computer programs, + * by storing the results of expensive function calls + * and returning the cached result when the same inputs occur again + * + * This function is a first class objects, + * which lets us use it as [Higher-Order Function](https://eloquentjavascript.net/05_higher_order.html) + * and return another function + * + * @param {Function} func Original function + * @returns {Function} Memoized function */ export const memoize = (func) => { - // Initializing new cache + // Initialization of a slot to store the function result const cache = {} return (...args) => { + // Retrieving the first argument of the function const [arg] = args + /** + * Checks if the argument is already present in the cache, + * then return the associated value / result + */ if (arg in cache) { - // Reading cache by argument return cache[arg] } - // Updating cache by argument + /** + * If the argument is not yet present in the cache, + * execute original function and save its value / result in cache, + * finally return it + */ const result = func(arg) cache[arg] = result return result From 90b04eadd48f3007d6e7d909a5e2159c2f6f3a68 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 5 Oct 2021 08:54:47 +0000 Subject: [PATCH 21/31] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 26ee705cb..a39b13bd8 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -57,6 +57,7 @@ * [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js) * [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js) * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/TitleCaseConversion.test.js) + * [UpperCaseConverstion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/UpperCaseConverstion.test.js) * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js) * [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js) From 6f9b1f127f8e05e4019d5d4057d3c705e3ad71ed Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 3 Oct 2021 19:54:17 +0200 Subject: [PATCH 22/31] Proposal: Clean up CI job a bit relates to #586 and #720 Added npm scripts for doctest and style checking via standard. This allows us to call those directly via npm and not via npx. The CI job itself is now split into distinct steps (makes it more visible which step failed). --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/nodejs.yml | 24 ------------------------ package.json | 4 +++- 3 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/nodejs.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..426766eee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: Continuous Integration + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: ๐Ÿ“ฆ Install dependencies + run: npm ci + env: + CI: true + + - name: ๐Ÿงช Run tests + run: | + npm run doctest || true # TODO: Add all doctests + npm test + env: + CI: true + + - name: ๐Ÿ’„ Code style + run: npm run style + env: + CI: true diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml deleted file mode 100644 index 39b9ee544..000000000 --- a/.github/workflows/nodejs.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Node CI -on: [push, pull_request] -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14.x] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - name: npm install, build, and test - run: | - npm install doctest standard --save-dev - npx doctest **/*.js || true # TODO: Add all doctests - npx standard - npm ci - npm run build --if-present - npm test - env: - CI: true diff --git a/package.json b/package.json index 0b8bfe122..c5a55fe84 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "A repository for All algorithms implemented in Javascript (for educational purposes only)", "main": "", "scripts": { - "test": "jest --no-cache" + "doctest": "doctest **/*.js", + "test": "jest --no-cache", + "style": "standard" }, "author": "TheAlgorithms", "license": "GPL-3.0", From 21d4096446efe5519818f1ff4d6788c1454d4710 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 3 Oct 2021 23:33:00 +0200 Subject: [PATCH 23/31] Another proposal: Clean up "update directory" job, as well relates to ##720 Cleaned up and updated the job description file a bit. Instead of attempting to commit every single time, we check if the DIRECTORY file actually has changes first. --- .github/workflows/commitAndPushDirectory.sh | 10 +++++++++ .github/workflows/update_directory_md.yml | 24 +++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100755 .github/workflows/commitAndPushDirectory.sh diff --git a/.github/workflows/commitAndPushDirectory.sh b/.github/workflows/commitAndPushDirectory.sh new file mode 100755 index 000000000..eb357addf --- /dev/null +++ b/.github/workflows/commitAndPushDirectory.sh @@ -0,0 +1,10 @@ +if ! git diff --quiet DIRECTORY.md; then + echo Changes found, attempting to commit and push... + git add DIRECTORY.md + git commit -am "Auto-update DIRECTORY.md" || true + git push --force origin HEAD:$GITHUB_REF || true + echo ... done. +else + echo No changes found, exiting. +fi + diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml index 3c6c333cb..530eb41db 100644 --- a/.github/workflows/update_directory_md.yml +++ b/.github/workflows/update_directory_md.yml @@ -1,18 +1,24 @@ # This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push -name: update_directory_md +name: Update Directory + on: [push] + jobs: - update_directory_md: + updateDirectory: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - uses: actions/setup-node@v1 - - run: | - node .github/workflows/UpdateDirectory.js + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: ๐Ÿ—„๏ธ Create Directory from JS files + run: node .github/workflows/UpdateDirectory.js + + - name: ๐Ÿค“ Commit & push new Directory (if needed) + run: | cat DIRECTORY.md git config --global user.name github-actions git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git add DIRECTORY.md - git commit -am "updating DIRECTORY.md" || true - git push --force origin HEAD:$GITHUB_REF || true + .github/workflows/commitAndPushDirectory.sh From f6396f48225b61544fe0d5d560b4a9b7013dcf2d Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 3 Oct 2021 23:35:11 +0200 Subject: [PATCH 24/31] Don't cat the full DIRECTORY.md file in the github job --- .github/workflows/update_directory_md.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml index 530eb41db..f2a86dad4 100644 --- a/.github/workflows/update_directory_md.yml +++ b/.github/workflows/update_directory_md.yml @@ -17,7 +17,6 @@ jobs: - name: ๐Ÿค“ Commit & push new Directory (if needed) run: | - cat DIRECTORY.md git config --global user.name github-actions git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY From 460fd57c6b77e2fd344f04e156186f8fe7a4b29c Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 3 Oct 2021 23:37:39 +0200 Subject: [PATCH 25/31] Test: Drop env.CI --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 426766eee..a3cac1724 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,17 +13,11 @@ jobs: - name: ๐Ÿ“ฆ Install dependencies run: npm ci - env: - CI: true - name: ๐Ÿงช Run tests run: | npm run doctest || true # TODO: Add all doctests npm test - env: - CI: true - name: ๐Ÿ’„ Code style run: npm run style - env: - CI: true From a69d9a8c4905d0815bca683a68d2246455b3b78b Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Mon, 4 Oct 2021 00:24:40 +0200 Subject: [PATCH 26/31] Clean up and speed up UpdateDirectory.js Uses globby to find all algorithm files. This is way quicker and less error-prone than the previous implementation. Plus, it allows us to fine-tune excludes (e.g. test files and the babel config). This also removes the need for setTimeouts which greatly speeds up the whole thing. --- .github/workflows/UpdateDirectory.js | 108 ------------------ .github/workflows/UpdateDirectory.mjs | 77 +++++++++++++ .github/workflows/update_directory_md.yml | 2 +- package-lock.json | 129 ++++++++++++++++++++++ package.json | 1 + 5 files changed, 208 insertions(+), 109 deletions(-) delete mode 100644 .github/workflows/UpdateDirectory.js create mode 100644 .github/workflows/UpdateDirectory.mjs diff --git a/.github/workflows/UpdateDirectory.js b/.github/workflows/UpdateDirectory.js deleted file mode 100644 index 6ab4e5796..000000000 --- a/.github/workflows/UpdateDirectory.js +++ /dev/null @@ -1,108 +0,0 @@ -// requiring path and fs modules -const path = require('path'); -const fs = require('fs'); - -let URL_BASE = "https://github.com/TheAlgorithms/Javascript/blob/master"; -let g_output = []; - -let filepaths = []; -function good_filepaths(top_dir = ".") { - fs.readdir(top_dir, function(err, list) { - if (err) { - console.log(err); - return; - } - list.forEach(function(file) { - let path = top_dir + "/" + file; - if (!file.startsWith(".")) { - fs.stat(path, function(err, stat) { - if (stat && stat.isDirectory()) { - good_filepaths(path); - } else { - if (file.toLowerCase().endsWith(".js")) { - filepaths.push(path.slice(2)); - } - } - }); - } - }); - }) -} - -function md_prefix(i) { - if (i) { - let res = ' '.repeat(i); - return res + "*"; - } else { - return "\n##" - } -} - -function print_path(old_path, new_path) { - let old_parts = old_path.split(path.sep); - let new_parts = new_path.split(path.sep); - for (let i = 0; i < new_parts.length; ++i) { - let new_part = new_parts[i]; - if (i + 1 > old_parts.len || old_parts[i] != new_part) { - if (new_part) { - g_output.push(`${md_prefix(i)} ${new_part.replace('_', ' ')}`); - } - } - } - return new_path; -} - -function build_directory_md(top_dir = ".") { - old_path = ""; - filepaths.sort(function(a, b) { - if (a.toLowerCase() < b.toLowerCase()) return -1; - if (a.toLowerCase() > b.toLowerCase()) return 1; - return 0; - }); - for (let filepath of filepaths) { - file = filepath.split(path.sep); - if (file.length == 1) { - filepath = ""; - filename = file[0]; - } else { - let total = file.length; - filename = file[total - 1]; - filepath = file.splice(0, total - 1).join(path.sep); - } - if (filepath != old_path) { - old_path = print_path(old_path, filepath); - } - let indent = 0; - for (let i = 0; i < filepath.length; ++i) { - if (filepath[i] == path.sep) { - ++indent; - } - } - if (filepath) { - ++indent; - } - let urls = [URL_BASE, filepath, filename]; - let url = urls.join("/").replace(" ", "%20"); - // remove extension from filename - filename = filename.split(".")[0]; - g_output.push(`${md_prefix(indent)} [${filename}](${url})`); - } - g_output = g_output.join('\n'); - return g_output; -} - -good_filepaths(); -setTimeout(() => { - // once the filepaths have been computed - build_directory_md(); - // console.log(filepaths); -}, 1000); -setTimeout(() => { - // once the g_output has been constructed, write to the file - fs.writeFile('DIRECTORY.md', g_output + '\n', (err) => { - if (err) { - console.log(err); - } - }) - // console.log(g_output); -}, 1000); diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs new file mode 100644 index 000000000..dc04b04a6 --- /dev/null +++ b/.github/workflows/UpdateDirectory.mjs @@ -0,0 +1,77 @@ +import path from 'path' +import fs from 'fs' +import { globby } from 'globby' + +const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master' + +function pathPrefix (i) { + if (i) { + const res = ' '.repeat(i) + return res + '*' + } else { + return '\n##' + } +} + +function printPath (oldPath, newPath, output) { + const oldParts = oldPath.split(path.sep) + const newParts = newPath.split(path.sep) + for (let i = 0; i < newParts.length; ++i) { + const newPart = newParts[i] + if (i + 1 > oldParts.length || oldParts[i] !== newPart) { + if (newPart) { + output.push(`${pathPrefix(i)} ${newPart.replace('_', ' ')}`) + } + } + } + return newPath +} + +function pathsToMarkdown (filePaths) { + const output = [] + + let oldPath = '' + filePaths.sort(function (a, b) { + if (a.toLowerCase() < b.toLowerCase()) return -1 + if (a.toLowerCase() > b.toLowerCase()) return 1 + return 0 + }) + for (let filepath of filePaths) { + const file = filepath.split(path.sep) + let filename = '' + if (file.length === 1) { + filepath = '' + filename = file[0] + } else { + const total = file.length + filename = file[total - 1] + filepath = file.splice(0, total - 1).join(path.sep) + } + if (filepath !== oldPath) { + oldPath = printPath(oldPath, filepath, output) + } + let indent = 0 + for (let i = 0; i < filepath.length; ++i) { + if (filepath[i] === path.sep) { + ++indent + } + } + if (filepath) { + ++indent + } + const urls = [URL_BASE, filepath, filename] + const url = urls.join('/').replace(' ', '%20') + // remove extension from filename + filename = filename.split('.')[0] + output.push(`${pathPrefix(indent)} [${filename}](${url})`) + } + + return output.join('\n') +} + +// get paths of all .js files - excluding node_modules, the .github folder, tests and config stuff +globby(['**/*.js', '!(node_modules|.github)/**/*', '!**/*.test.js', '!babel.config.js']) + // create markdown content + .then(pathsToMarkdown) + // write markdown to file + .then(markdown => fs.writeFileSync('DIRECTORY.md', markdown + '\n', { encoding: 'utf8' })) diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml index f2a86dad4..e29367841 100644 --- a/.github/workflows/update_directory_md.yml +++ b/.github/workflows/update_directory_md.yml @@ -13,7 +13,7 @@ jobs: node-version: '14' - name: ๐Ÿ—„๏ธ Create Directory from JS files - run: node .github/workflows/UpdateDirectory.js + run: node .github/workflows/UpdateDirectory.mjs - name: ๐Ÿค“ Commit & push new Directory (if needed) run: | diff --git a/package-lock.json b/package-lock.json index 1cfe68558..dcd355621 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2173,6 +2173,32 @@ } } }, + "@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + } + }, "@sinonjs/commons": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz", @@ -2430,6 +2456,12 @@ "is-string": "^1.0.5" } }, + "array-union": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-3.0.1.tgz", + "integrity": "sha512-1OvF9IbWwaeiM9VhzYXVQacMibxpXOMYVNIvMtKRyX9SImBXpKcFr8XvFDeEslCyuH/t6KRt7HEO94AlP8Iatw==", + "dev": true + }, "array-unique": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", @@ -3199,6 +3231,23 @@ "integrity": "sha512-ZXx86srb/iYy6jG71k++wBN9P9J05UNQ5hQHQd9MtMPvcqXPx/vKU69jfHV637D00Q2gSgPk2D+jSx3l1lDW/Q==", "dev": true }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + }, + "dependencies": { + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + } + } + }, "doctest": { "version": "0.17.1", "resolved": "https://registry.npmjs.org/doctest/-/doctest-0.17.1.tgz", @@ -3909,6 +3958,37 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "fast-glob": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", + "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "dependencies": { + "micromatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", + "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.2.3" + } + }, + "picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "dev": true + } + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -3919,6 +3999,15 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, + "fastq": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", + "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, "fb-watchman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.1.tgz", @@ -4119,6 +4208,34 @@ "type-fest": "^0.8.1" } }, + "globby": { + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-12.0.2.tgz", + "integrity": "sha512-lAsmb/5Lww4r7MM9nCCliDZVIKbZTavrsunAsHLr9oHthrZP1qi7/gAnHOsUs9bLvEt2vKVJhHmxuL7QbDuPdQ==", + "dev": true, + "requires": { + "array-union": "^3.0.1", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.7", + "ignore": "^5.1.8", + "merge2": "^1.4.1", + "slash": "^4.0.0" + }, + "dependencies": { + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + }, + "slash": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", + "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", + "dev": true + } + } + }, "graceful-fs": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", @@ -7245,6 +7362,12 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, "micromatch": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", @@ -8278,6 +8401,12 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", diff --git a/package.json b/package.json index c5a55fe84..d52c3788e 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "babel-jest": "^26.3.0", "doctest": "^0.17.1", + "globby": "^12.0.2", "jest": "^26.4.2", "standard": "^14.3.4" } From 6fe322bd8afbc6032b9e075b1d9686386a0d533d Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Mon, 4 Oct 2021 00:27:11 +0200 Subject: [PATCH 27/31] Add npm ci to directory-updating job, as well (so that we can utilize globby) --- .github/workflows/update_directory_md.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml index e29367841..b2eeb9919 100644 --- a/.github/workflows/update_directory_md.yml +++ b/.github/workflows/update_directory_md.yml @@ -12,6 +12,9 @@ jobs: with: node-version: '14' + - name: ๐Ÿ“ฆ Install dependencies + run: npm ci + - name: ๐Ÿ—„๏ธ Create Directory from JS files run: node .github/workflows/UpdateDirectory.mjs From 7bb3c80f052b8a4b09c5e6d3e6dea09388855b92 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Tue, 5 Oct 2021 10:19:06 +0200 Subject: [PATCH 28/31] Fix URL creation in directory markdown --- .github/workflows/UpdateDirectory.mjs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/UpdateDirectory.mjs b/.github/workflows/UpdateDirectory.mjs index dc04b04a6..21b7db7e1 100644 --- a/.github/workflows/UpdateDirectory.mjs +++ b/.github/workflows/UpdateDirectory.mjs @@ -59,11 +59,17 @@ function pathsToMarkdown (filePaths) { if (filepath) { ++indent } - const urls = [URL_BASE, filepath, filename] - const url = urls.join('/').replace(' ', '%20') + + // prepare the markdown-esque prefix to the file's line + const prefix = pathPrefix(indent) + // remove extension from filename - filename = filename.split('.')[0] - output.push(`${pathPrefix(indent)} [${filename}](${url})`) + const name = filename.split('.')[0] + + // create URL to the actual file on github + const url = encodeURI([URL_BASE, filepath, filename].join('/')) + + output.push(`${prefix} [${name}](${url})`) } return output.join('\n') From 565ce68027a6fad33a04b28bf5a4b24efff068cb Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Tue, 5 Oct 2021 10:28:38 +0200 Subject: [PATCH 29/31] Update DIRECTORY.md (manually after a rebase) --- DIRECTORY.md | 98 ---------------------------------------------------- 1 file changed, 98 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index a39b13bd8..f5f8200f6 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,6 +1,4 @@ -## [babel](https://github.com/TheAlgorithms/Javascript/blob/master//babel.config.js) - ## Backtracking * [GeneratePermutations](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/GeneratePermutations.js) * [KnightTour](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/KnightTour.js) @@ -8,17 +6,10 @@ * [RatInAMaze](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/RatInAMaze.js) * [Sudoku](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/Sudoku.js) * [SumOfSubset](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/SumOfSubset.js) - * tests - * [NQueen](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/NQueen.test.js) - * [RatInAMaze](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/RatInAMaze.test.js) - * [Sudoku](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/Sudoku.test.js) - * [SumOfSubset](https://github.com/TheAlgorithms/Javascript/blob/master/Backtracking/tests/SumOfSubset.test.js) ## Bit-Manipulation * [BinaryCountSetBits](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/BinaryCountSetBits.js) * [SetBit](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/SetBit.js) - * test - * [SetBit](https://github.com/TheAlgorithms/Javascript/blob/master/Bit-Manipulation/test/SetBit.test.js) ## Cache * [LFUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LFUCache.js) @@ -53,18 +44,12 @@ * [RgbHsvConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RgbHsvConversion.js) * [RGBToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RGBToHex.js) * [RomanToDecimal](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/RomanToDecimal.js) - * test - * [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js) - * [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js) - * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/TitleCaseConversion.test.js) - * [UpperCaseConverstion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/UpperCaseConverstion.test.js) * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js) * [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js) ## Data-Structures * Array * [QuickSelect](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Array/QuickSelect.js) - * [QuickSelect](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Array/QuickSelect.test.js) * Graph * [Graph](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph.js) * [Graph2](https://github.com/TheAlgorithms/Javascript/blob/master/Data-Structures/Graph/Graph2.js) @@ -109,11 +94,6 @@ * [Shuf](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/Shuf.js) * [SieveOfEratosthenes](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/SieveOfEratosthenes.js) * [SudokuSolver](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/SudokuSolver.js) - * tests - * [CoinChange](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/CoinChange.test.js) - * [LongestPalindromicSubsequence](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/LongestPalindromicSubsequence.test.js) - * [LongestValidParentheses](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/LongestValidParentheses.test.js) - * [TrappingRainWater](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/tests/TrappingRainWater.test.js) * [TrappingRainWater](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/TrappingRainWater.js) * [ZeroOneKnapsack](https://github.com/TheAlgorithms/Javascript/blob/master/Dynamic-Programming/ZeroOneKnapsack.js) @@ -135,8 +115,6 @@ * [NodeNeighbors](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/NodeNeighbors.js) * [NumberOfIslands](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/NumberOfIslands.js) * [PrimMST](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/PrimMST.js) - * test - * [BellmanFord](https://github.com/TheAlgorithms/Javascript/blob/master/Graphs/test/BellmanFord.test.js) ## Hashes * [SHA1](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA1.js) @@ -201,52 +179,11 @@ * [Softmax](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Softmax.js) * [SquareRoot](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SquareRoot.js) * [SumOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SumOfDigits.js) - * test - * [Abs](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Abs.test.js) - * [Area](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Area.test.js) - * [ArmstrongNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ArmstrongNumber.test.js) - * [AverageMean](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/AverageMean.test.js) - * [AverageMedian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/AverageMedian.test.js) - * [BInaryConvert](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/BInaryConvert.test.js) - * [BinaryExponentiationIterative](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/BinaryExponentiationIterative.test.js) - * [Coordinate](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Coordinate.test.js) - * [DegreeToRadian](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/DegreeToRadian.test.js) - * [DigitSum](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/DigitSum.test.js) - * [EulersTotientFunction](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/EulersTotientFunction.test.js) - * [Factorial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Factorial.test.js) - * [Factors](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Factors.test.js) - * [FareyApproximation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FareyApproximation.test.js) - * [Fibonacci](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Fibonacci.test.js) - * [FindHcf](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FindHcf.test.js) - * [FindLcm](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/FindLcm.test.js) - * [GridGet](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/GridGet.test.js) - * [IsDivisible](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/IsDivisible.test.js) - * [IsEven](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/IsEven.test.js) - * [MeanSquareError](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/MeanSquareError.test.js) - * [ModularBinaryExponentiationRecursive](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ModularBinaryExponentiationRecursive.test.js) - * [NumberOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/NumberOfDigits.test.js) - * [Palindrome](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Palindrome.test.js) - * [PascalTriangle](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PascalTriangle.test.js) - * [PerfectCube](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectCube.test.js) - * [PerfectNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectNumber.test.js) - * [PerfectSquare](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PerfectSquare.test.js) - * [PiApproximationMonteCarlo](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PiApproximationMonteCarlo.test.js) - * [Polynomial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Polynomial.test.js) - * [Pow](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Pow.test.js) - * [PrimeCheck](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/PrimeCheck.test.js) - * [RadianToDegree](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/RadianToDegree.test.js) - * [ReversePolishNotation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/ReversePolishNotation.test.js) - * [SieveOfEratosthenes](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/SieveOfEratosthenes.test.js) - * [Softmax](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Softmax.test.js) - * [SumOfDigits](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/SumOfDigits.test.js) - * [Volume](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/test/Volume.test.js) * [Volume](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Volume.js) * [WhileLoopFactorial](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/WhileLoopFactorial.js) ## Navigation * [Haversine](https://github.com/TheAlgorithms/Javascript/blob/master/Navigation/Haversine.js) - * test - * [Haversine](https://github.com/TheAlgorithms/Javascript/blob/master/Navigation/test/Haversine.test.js) ## Project-Euler * [Problem013](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem013.js) @@ -263,9 +200,6 @@ * [Problem7](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem7.js) * [Problem8](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem8.js) * [Problem9](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/Problem9.js) - * test - * [Problem10](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/test/Problem10.test.js) - * [Problem8](https://github.com/TheAlgorithms/Javascript/blob/master/Project-Euler/test/Problem8.test.js) ## Recursive * [BinaryEquivalent](https://github.com/TheAlgorithms/Javascript/blob/master/Recursive/BinaryEquivalent.js) @@ -290,9 +224,6 @@ * [SlidingWindow](https://github.com/TheAlgorithms/Javascript/blob/master/Search/SlidingWindow.js) * [StringSearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/StringSearch.js) * [TernarySearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/TernarySearch.js) - * test - * [SlidingWindow](https://github.com/TheAlgorithms/Javascript/blob/master/Search/test/SlidingWindow.test.js) - * [TernarySearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/test/TernarySearch.test.js) ## Sorts * [BeadSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BeadSort.js) @@ -319,10 +250,6 @@ * [RadixSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/RadixSort.js) * [SelectionSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/SelectionSort.js) * [ShellSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/ShellSort.js) - * test - * [FisherYatesShuffle](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/FisherYatesShuffle.test.js) - * [QuickSortRecursive](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/QuickSortRecursive.test.js) - * [SelectionSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/test/SelectionSort.test.js) * [TimSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/TimSort.js) * [TopologicalSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/TopologicalSort.js) * [WiggleSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/WiggleSort.js) @@ -354,36 +281,11 @@ * [ReverseString](https://github.com/TheAlgorithms/Javascript/blob/master/String/ReverseString.js) * [ReverseWords](https://github.com/TheAlgorithms/Javascript/blob/master/String/ReverseWords.js) * [ScrambleStrings](https://github.com/TheAlgorithms/Javascript/blob/master/String/ScrambleStrings.js) - * test - * [CheckAnagram](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckAnagram.test.js) - * [CheckCamelCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckCamelCase.test.js) - * [CheckFlatCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckFlatCase.test.js) - * [CheckPalindrome](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckPalindrome.test.js) - * [CheckPangram](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckPangram.test.js) - * [CheckSnakeCase](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckSnakeCase.test.js) - * [CheckVowels](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckVowels.test.js) - * [CheckWordOcurrence](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CheckWordOcurrence.test.js) - * [CreatePermutations](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/CreatePermutations.test.js) - * [DiceCoefficient](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/DiceCoefficient.test.js) - * [FormatPhoneNumber](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/FormatPhoneNumber.test.js) - * [HammingDistance](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/HammingDistance.test.js) - * [KMPPatternSearching](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/KMPPatternSearching.test.js) - * [LevenshteinDistance](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/LevenshteinDistance.test.js) - * [MaxCharacter](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/MaxCharacter.test.js) - * [MaxWord](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/MaxWord.test.js) - * [PatternMatching](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/PatternMatching.test.js) - * [PermutateString](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/PermutateString.test.js) - * [ReverseString](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ReverseString.test.js) - * [ReverseWords](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ReverseWords.test.js) - * [ScrambleStrings](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ScrambleStrings.test.js) - * [ValidateEmail](https://github.com/TheAlgorithms/Javascript/blob/master/String/test/ValidateEmail.test.js) * [ValidateEmail](https://github.com/TheAlgorithms/Javascript/blob/master/String/ValidateEmail.js) ## Timing-Functions * [GetMonthDays](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/GetMonthDays.js) * [IntervalTimer](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/IntervalTimer.js) - * test - * [GetMonthDays](https://github.com/TheAlgorithms/Javascript/blob/master/Timing-Functions/test/GetMonthDays.test.js) ## Trees * [BreadthFirstTreeTraversal](https://github.com/TheAlgorithms/Javascript/blob/master/Trees/BreadthFirstTreeTraversal.js) From 42549056b9d4dcdd14d488c3143581e6a3d03e09 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:33:19 +0000 Subject: [PATCH 30/31] updating DIRECTORY.md --- DIRECTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index a39b13bd8..226d6545c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -23,6 +23,9 @@ ## Cache * [LFUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LFUCache.js) * [LRUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LRUCache.js) + * [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/Memoize.js) + * test + * [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/test/Memoize.test.js) ## Cellular-Automata * [ConwaysGameOfLife](https://github.com/TheAlgorithms/Javascript/blob/master/Cellular-Automata/ConwaysGameOfLife.js) From 7af7a1fa74eaa6a55e0392afea4c5bb1ca99549f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 5 Oct 2021 09:39:05 +0000 Subject: [PATCH 31/31] Auto-update DIRECTORY.md --- DIRECTORY.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 3a2c90115..d63e09657 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -15,8 +15,6 @@ * [LFUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LFUCache.js) * [LRUCache](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/LRUCache.js) * [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/Memoize.js) - * test - * [Memoize](https://github.com/TheAlgorithms/Javascript/blob/master/Cache/test/Memoize.test.js) ## Cellular-Automata * [ConwaysGameOfLife](https://github.com/TheAlgorithms/Javascript/blob/master/Cellular-Automata/ConwaysGameOfLife.js)