From cba1c31b44b6b6d4ed7cae2de3ef6977560aebb0 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:39:18 +0530 Subject: [PATCH 01/62] chore: remove codespell from ci --- .github/workflows/ci.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 447eccc501..624b4eac82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,11 +20,4 @@ jobs: - name: 💄 Code style run: npm run style - codespell: - name: Check for spelling errors - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: codespell-project/actions-codespell@master - with: - check_filenames: true + From 662590b647039ac4037177b1717ce77b2bfc768a Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:41:37 +0530 Subject: [PATCH 02/62] feat: add codespell workflow --- .github/workflows/codespell.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/codespell.yml diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 0000000000..ddf345b513 --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,13 @@ +name: codespell +on: [push, pull_request] +jobs: + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: codespell-project/actions-codespell@master + with: + check_filenames: true + skip: *.json,*.yml + From 64f924f6748a954f7e8ab1d5132155318ab6ebf6 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:45:01 +0530 Subject: [PATCH 03/62] fix: codespell workflow --- .github/workflows/codespell.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index ddf345b513..4c5e6fd586 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -9,5 +9,6 @@ jobs: - uses: codespell-project/actions-codespell@master with: check_filenames: true - skip: *.json,*.yml + # file types to ignore + skip: "*.json,*.yml" From 8adea3911fe77efe1a4ee38a61acc0ec61ce2520 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:47:35 +0530 Subject: [PATCH 04/62] fix: ignore spellings in directory --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 4c5e6fd586..e96cc46476 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml" + skip: "*.json,*.yml,DIRECTORY.md" From 6f61a3a7681b6639345ff854a67d6f99b5cfd145 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:49:56 +0530 Subject: [PATCH 05/62] chore: fix spellings ./Dynamic-Programming/KadaneAlgo.js:2: contiguos ==> contiguous ./Dynamic-Programming/KadaneAlgo.js:14: posible ==> possible --- Dynamic-Programming/KadaneAlgo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dynamic-Programming/KadaneAlgo.js b/Dynamic-Programming/KadaneAlgo.js index e436b6edd8..a4c423e0f1 100644 --- a/Dynamic-Programming/KadaneAlgo.js +++ b/Dynamic-Programming/KadaneAlgo.js @@ -1,5 +1,5 @@ /* Kadane's algorithm is one of the most efficient ways to - * calculate the maximum contiguos subarray sum for a given array. + * calculate the maximum contiguous subarray sum for a given array. * Below is the implementation of kadanes's algorithm along with * some sample test cases. * There might be a special case in this problem if al the elements @@ -11,7 +11,7 @@ export function kadaneAlgo (array) { let cummulativeSum = 0 - let maxSum = Number.NEGATIVE_INFINITY // maxSum has the least posible value + let maxSum = Number.NEGATIVE_INFINITY // maxSum has the least possible value for (let i = 0; i < array.length; i++) { cummulativeSum = cummulativeSum + array[i] if (maxSum < cummulativeSum) { From 285fcf0c05c329a7b0009246f6585111cb2445ce Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:52:16 +0530 Subject: [PATCH 06/62] chore: fix spelling ./Dynamic-Programming/SieveOfEratosthenes.js:4: upto ==> up to --- Dynamic-Programming/SieveOfEratosthenes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic-Programming/SieveOfEratosthenes.js b/Dynamic-Programming/SieveOfEratosthenes.js index 2203e3fd7f..4fb1b47b52 100644 --- a/Dynamic-Programming/SieveOfEratosthenes.js +++ b/Dynamic-Programming/SieveOfEratosthenes.js @@ -1,7 +1,7 @@ function sieveOfEratosthenes (n) { /* * Calculates prime numbers till a number n - * :param n: Number upto which to calculate primes + * :param n: Number up to which to calculate primes * :return: A boolean list containing only primes */ const primes = new Array(n + 1) From bd9c14480419953e56eaafb1291229a39bd4d8f1 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:53:59 +0530 Subject: [PATCH 07/62] chore: fix spellings ./Dynamic-Programming/MaxNonAdjacentSum.js:22: Exmaple ==> Example --- Dynamic-Programming/MaxNonAdjacentSum.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic-Programming/MaxNonAdjacentSum.js b/Dynamic-Programming/MaxNonAdjacentSum.js index d1b4c93a8d..e7803b6a23 100644 --- a/Dynamic-Programming/MaxNonAdjacentSum.js +++ b/Dynamic-Programming/MaxNonAdjacentSum.js @@ -19,7 +19,7 @@ function maximumNonAdjacentSum (nums) { return Math.max(maxExcluding, maxIncluding) } -// Exmaple +// Example // maximumNonAdjacentSum([1, 2, 3])) // maximumNonAdjacentSum([1, 5, 3, 7, 2, 2, 6])) From 5aa5091827be55961722c5621030d216d96e17ed Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:34:24 +0530 Subject: [PATCH 08/62] chore: fix spelling ./Project-Euler/test/Problem010.test.js:4: upto ==> up to ./Project-Euler/test/Problem010.test.js:8: upto ==> up to ./Project-Euler/test/Problem010.test.js:12: upto ==> up to --- Project-Euler/test/Problem010.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project-Euler/test/Problem010.test.js b/Project-Euler/test/Problem010.test.js index da551e4fa9..2169cabc12 100644 --- a/Project-Euler/test/Problem010.test.js +++ b/Project-Euler/test/Problem010.test.js @@ -1,15 +1,15 @@ import { calculateSumOfPrimeNumbers } from '../Problem010' describe('checkAnagram', () => { - it('Return the sum of prime numbers upto but less than 14', () => { + it('Return the sum of prime numbers up to but less than 14', () => { const SUT = calculateSumOfPrimeNumbers(14) expect(SUT).toBe(41) }) - it('Return the sum of prime numbers upto but less than 10', () => { + it('Return the sum of prime numbers up to but less than 10', () => { const SUT = calculateSumOfPrimeNumbers(10) expect(SUT).toBe(17) }) - it('Return the sum of prime numbers upto but less than 100', () => { + it('Return the sum of prime numbers up to but less than 100', () => { const SUT = calculateSumOfPrimeNumbers(100) expect(SUT).toBe(1060) }) From f03712e1087134da15429cdefcbe57d759af7bdd Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:36:11 +0530 Subject: [PATCH 09/62] chore: fix spelling ./String/AlphaNumericPalindrome.js:10: recieves ==> receives ./String/AlphaNumericPalindrome.js:10: sting ==> string ./String/AlphaNumericPalindrome.js:46: varaible ==> variable --- String/AlphaNumericPalindrome.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/String/AlphaNumericPalindrome.js b/String/AlphaNumericPalindrome.js index 2d1a071a29..ee3ca6cbf7 100644 --- a/String/AlphaNumericPalindrome.js +++ b/String/AlphaNumericPalindrome.js @@ -7,7 +7,7 @@ /***************************************************************************** * What is a palindrome? https://en.wikipedia.org/wiki/Palindrome * - * The function alphaNumericPlaindrome() recieves a sting with varying formats + * The function alphaNumericPlaindrome() receives a string with varying formats * like "racecar", "RaceCar", and "race CAR" * The string can also have special characters * like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2" @@ -43,7 +43,7 @@ const alphaNumericPlaindrome = (str) => { // iterate through the arr and check the condition of palindrome for (let i = 0; i < arr.length; i++) { if (arr[i] !== arrRev[arr.length - 1 - i]) { - // if the string is not palindrome then we change palin varaible to 1 + // if the string is not palindrome then we change palin variable to 1 palin = 1 } } From 2c4d6a283c289ea86ac20daf6d52adadb303ef3c Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:37:16 +0530 Subject: [PATCH 10/62] chore: fix spelling ./String/DiceCoefficient.js:3: stings ==> strings --- String/DiceCoefficient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/DiceCoefficient.js b/String/DiceCoefficient.js index ca9471159b..f12bb0cae3 100644 --- a/String/DiceCoefficient.js +++ b/String/DiceCoefficient.js @@ -1,6 +1,6 @@ /* The Sørensen–Dice coefficient is a statistic used to gauge the similarity of two samples. * Applied to strings, it can give you a value between 0 and 1 (included) which tells you how similar they are. - * Dice coefficient is calculated by comparing the bigrams of both stings, + * Dice coefficient is calculated by comparing the bigrams of both strings, * a bigram is a substring of the string of length 2. * read more: https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient */ From 18968438b4e8c7ab34a81146c81ae41bd6df5f89 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:38:11 +0530 Subject: [PATCH 11/62] chore: fix spelling ./String/test/DiceCoefficient.test.js:9: atleast ==> at least --- String/test/DiceCoefficient.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/test/DiceCoefficient.test.js b/String/test/DiceCoefficient.test.js index f61f5848ba..cdad3d4c7a 100644 --- a/String/test/DiceCoefficient.test.js +++ b/String/test/DiceCoefficient.test.js @@ -6,7 +6,7 @@ describe('diceCoefficient', () => { expect(diceCoefficient('abc', 'abc')).toBe(1) expect(diceCoefficient('', '')).toBe(1) - // string length needs to be atleast 2 (unless equal) + // string length needs to be at least 2 (unless equal) expect(diceCoefficient('a', '')).toBe(0) expect(diceCoefficient('', 'a')).toBe(0) From c6b8b6a14454ea5bef8595fad4fa999792b49ce1 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:40:00 +0530 Subject: [PATCH 12/62] chore: fix spelling ./String/test/MaxWord.test.js:8: ba ==> be --- String/test/MaxWord.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/String/test/MaxWord.test.js b/String/test/MaxWord.test.js index 417f1232d5..b2d902c54a 100644 --- a/String/test/MaxWord.test.js +++ b/String/test/MaxWord.test.js @@ -5,8 +5,8 @@ describe('Testing the maxWord function', () => { expect(() => maxWord(10)).toThrow() }) it('get the max word', () => { - const string = 'ba ba ba ba banana' + const string = 'be be be be a a banana' const mostOccurringWord = maxWord(string) - expect(mostOccurringWord).toBe('ba') + expect(mostOccurringWord).toBe('be') }) }) From c5f644b805cdb147dcbfb700f8f80bfa562ac747 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:42:55 +0530 Subject: [PATCH 13/62] chore: ignore `PermutateString.test.js` --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index e96cc46476..b01ad71ffb 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml,DIRECTORY.md" + skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js" From 56084c1564e81ecf56af2b9581b6c4f19d1ab779 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:44:07 +0530 Subject: [PATCH 14/62] chore: fix spelling ./String/test/CheckVowels.test.js:62: occurances ==> occurrences --- String/test/CheckVowels.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/test/CheckVowels.test.js b/String/test/CheckVowels.test.js index e430fd4a2d..e46cd7de1d 100644 --- a/String/test/CheckVowels.test.js +++ b/String/test/CheckVowels.test.js @@ -59,7 +59,7 @@ describe('Test the checkVowels function', () => { expect(countVowels).toBe(0) }) - it('should count multiple occurances of the same vowel in the input', () => { + it('should count multiple occurrences of the same vowel in the input', () => { const value = 'aaaaa' const countVowels = checkVowels(value) expect(countVowels).toBe(5) From c7a3bbe1c164c6fa5bb461d98bb53f525eb0284b Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:54:18 +0530 Subject: [PATCH 15/62] chore: ignore `SubsequenceRecursive.js` --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index b01ad71ffb..e43035867f 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js" + skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js,SubsequenceRecursive.js" From 56c96f21062cff6750c8dec05946a8359fd50408 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:55:49 +0530 Subject: [PATCH 16/62] chore: fix spelling ./Conversions/TemperatureConversion.js:2: arguement ==> argument --- Conversions/TemperatureConversion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Conversions/TemperatureConversion.js b/Conversions/TemperatureConversion.js index 8bf9130b18..d5b5452f7d 100644 --- a/Conversions/TemperatureConversion.js +++ b/Conversions/TemperatureConversion.js @@ -1,5 +1,5 @@ // This files has functions to convert different temperature units -// Functions take temperature value as a arguement and returns corresponding converted value +// Functions take temperature value as a argument and returns corresponding converted value const celsiusToFahrenheit = (celsius) => { // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -40,7 +40,7 @@ const fahrenheitToRankine = (fahrenheit) => { const kelvinToCelsius = (kelvin) => { // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius - return Math.round((kelvin) - 273.15) + return Math.round((kelvin) - 273.15) } const kelvinToFahrenheit = (kelvin) => { From c5a57e839937eff18d0f6a473581765e23d900bb Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:56:35 +0530 Subject: [PATCH 17/62] chore: fix spelling ./Conversions/RailwayTimeConversion.js:7: Formate ==> Format ./Conversions/RailwayTimeConversion.js:8: Formate ==> Format --- Conversions/RailwayTimeConversion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Conversions/RailwayTimeConversion.js b/Conversions/RailwayTimeConversion.js index dd06487e13..2537cf4495 100644 --- a/Conversions/RailwayTimeConversion.js +++ b/Conversions/RailwayTimeConversion.js @@ -4,8 +4,8 @@ some changes on hours and minutes and if the time in 'PM' it means the only want some changes in hour value. - Input Formate -> 07:05:45PM - Output Formate -> 19:05:45 + Input Format -> 07:05:45PM + Output Format -> 19:05:45 Problem & Explanation Source : https://www.mathsisfun.com/time.html */ From b0b1c5ee7efb2317fa95438b8d69f5a03c999b7e Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:39:36 +0530 Subject: [PATCH 18/62] chore: remove Linear Algebra The deleted directory hosted a package which are not accepted by this repository. --- Linear-Algebra/README.md | 114 ----------- Linear-Algebra/package-lock.json | 171 ----------------- Linear-Algebra/package.json | 17 -- Linear-Algebra/src/la_lib.js | 313 ------------------------------- Linear-Algebra/test/test.js | 213 --------------------- 5 files changed, 828 deletions(-) delete mode 100644 Linear-Algebra/README.md delete mode 100644 Linear-Algebra/package-lock.json delete mode 100644 Linear-Algebra/package.json delete mode 100644 Linear-Algebra/src/la_lib.js delete mode 100644 Linear-Algebra/test/test.js diff --git a/Linear-Algebra/README.md b/Linear-Algebra/README.md deleted file mode 100644 index 3f3a922d20..0000000000 --- a/Linear-Algebra/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# Linear algebra library for JavaScript - -This library contains some useful classes and functions for dealing with linear algebra in JavaScript. -The library was orginal written in **TypeScript** and then compiles into pure JavaScript. - ---- - -## Overview - -- class Vector : This class represents a vector of arbitray size and operations on it. - - constructor Vector(N) : creates a zero vector of size N - - constructor Vector(N, components) : creates a vector of size N with the given components. - - createUnitBasis(pos) : converts this vector in a unit basis vector and returns it. - - component(pos) : returns the specified component (indexing at 0) - - changeComponent(pos, value) : change the specified component. - - toString() : returns a string representation of this vector. - - size() : returns the size of the vector. (not the eulidean length!) - - eulideanLength() : computes the eulidean length of this vector. - - add(other) : vector addition, returns the rersult. - - sub(other) : vector subtraction, returns the rersult. - - dot(other) : computes the dot-product and returns it. - - scalar(s) : scalar (s) multiplication. returns the result. - - norm() : normalizes this vector and returns it. - - equal(other) : returns true if the vectors are equal, otherwise false. - -- function unitBasisVector(N,pos) : returns a unit basis vector of size N with a One on position 'pos' -- function randomVectorInt(N,a,b) : returns a random vector with integer components (between 'a' and 'b') of size N. -- function randomVectorFloat(N,a,b) : returns a random vector with floating point components (between 'a' and 'b') of size N. - -- class Matrix : This class represents a matrix of arbitrary size and operations on it. - - constructor(rows, cols) : creates a zero matrix of dimension rows x cols. - - constructor(rows, cols, components) : creates a matrix with fix numbers of dimension rows x cols. - - component(x,y) : returns the specified component. - - changeComponent(x,y,value) : changes the specified component with the new value 'value'. - - toString() : returns a string representation of this matrix. - - dimension() : returns the dimension of this matrix as number arras [rows,cols]. - - add(other) : returns the result of the matrix addition. - - equal(other) : returns true if the matrices are equal, otherwise false. - - scalar(c) : returns the result of the matrix-scalar multiplication. ---- - -## Documentation - -The module is well documented in its source code. Look in the TypeScript file ```la_lib.ts```. - ---- - -## Usage - -You will find the library in the **src** directory its called ```la_lib.js```. You simply need to -include this library in your project **(you don't install anything)**. After that: - -```js - var x = LinearAlgebra.Vector(...); -``` - -The namespace LinearAlgebra contains useful classes and functions for dealing with linear algebra under JavaScript. - -Some examples: - -```js -// ---------------------------- Examples ------------------------------------------ - -// creates vectors -var x = new LinearAlgebra.Vector(5, [1, 2, 3, 4, 5]); -var y = new LinearAlgebra.Vector(5, [1, 2, 3, 4, 5]); - -// prints size of the vector -console.log(x.size()); // ==> 5 - -// changes the 2-th component with 7 -//x.changeComponent(2,7); - -// print the 2-th component. -console.log(x.component(2)); // ==> 3 - -// prints the full vector as string. -console.log(x.toString()); // ==> (1,2,3,4,5) - -// vector addition -console.log(x.add(y).toString()); // ==> (2,3,6,8,10) - -//console.log(x.createUnitBasis(1).toString()); - -// computes the dot-product -console.log(x.dot(y)); // ==> 55 - -// computes and prints the scalar-product -console.log(x.scalar(5).toString()); // ==> (5,10,15,20,25) - -// creates a unit basis vector -console.log(LinearAlgebra.unitBasisVector(3, 0).toString()); // ==> (1,0,0) - -// creates random vectors -console.log(LinearAlgebra.randomVectorInt(3, 0, 5).toString()); -console.log(LinearAlgebra.randomVectorFloat(3, 0, 5).toString()); -``` - ---- - -## Tests - -Go in the directory of the project and type in: -```npm install``` -```npm test``` -The test-suite use the JavaScript test-framework **mocha**. - ---- - -## Contributing - -You can contribute to this project. Feel free and pull request some new features or documention. -**TODO:** Global functions for special matrices. -**TODO:** Documention of the classes and functions. diff --git a/Linear-Algebra/package-lock.json b/Linear-Algebra/package-lock.json deleted file mode 100644 index 1492a09eed..0000000000 --- a/Linear-Algebra/package-lock.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "name": "linear-algebra-javascript", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "browser-stdout": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", - "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==" - }, - "commander": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "diff": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", - "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==" - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "growl": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", - "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==" - }, - "has-flag": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" - }, - "he": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "1.1.11" - } - }, - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "requires": { - "minimist": "0.0.8" - } - }, - "mocha": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.2.tgz", - "integrity": "sha512-nmlYKMRpJZLxgzk0bRhcvlpjSisbi0x1JiRl7kctadOMPmecUie7WwCZmcyth+PzX5txKbpcMIvDZCAlx9ISxg==", - "requires": { - "browser-stdout": "1.3.1", - "commander": "2.11.0", - "debug": "3.1.0", - "diff": "3.3.1", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.3", - "he": "1.1.1", - "mkdirp": "0.5.1", - "supports-color": "4.4.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", - "requires": { - "has-flag": "2.0.0" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - } - } -} diff --git a/Linear-Algebra/package.json b/Linear-Algebra/package.json deleted file mode 100644 index 1631a3f9a7..0000000000 --- a/Linear-Algebra/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "linear-algebra-javascript", - "version": "1.0.0", - "description": "simple linear algebra library for JavaScript", - "main": "index.js", - "directories": { - "test": "test" - }, - "scripts": { - "test": "mocha" - }, - "author": "Christian Bender", - "license": "MIT", - "dependencies": { - "mocha": "^5.0.2" - } -} diff --git a/Linear-Algebra/src/la_lib.js b/Linear-Algebra/src/la_lib.js deleted file mode 100644 index 72d8473e8c..0000000000 --- a/Linear-Algebra/src/la_lib.js +++ /dev/null @@ -1,313 +0,0 @@ -/* - author: Christian Bender - license: MIT-license - - The namespace LinearAlgebra contains useful classes and functions for dealing with - linear algebra under JavaScript. -*/ -let LinearAlgebra; -(function (LinearAlgebra) { - /* - class: Vector - This class represents a vector of arbitrary size and operations on it. - */ - const Vector = /** @class */ (function () { - // constructor - function Vector (N, comps) { - if (comps === undefined) { - comps = [] - } - this.components = new Array(N) - if (comps.length === 0) { - for (let i = 0; i < N; i++) { - this.components[i] = 0.0 - } - } else { - if (N === comps.length) { - this.components = comps - } else { - throw new Error('Vector: invalid size!') - } - } - } // end of constructor - // returns the size of this vector. - // not the eulidean length! - Vector.prototype.size = function () { - return this.components.length - } - // computes the eulidean length. - Vector.prototype.eulideanLength = function () { - let sum = 0 - for (let i = 0; i < this.components.length; i++) { - sum += this.components[i] * this.components[i] - } - return Math.sqrt(sum) - } - // getter for the components of the vector. - // returns a specified component (index) - Vector.prototype.component = function (index) { - return this.components[index] - } - // setter for a specified component of this vector. - Vector.prototype.changeComponent = function (index, value) { - if (index >= 0 && index < this.components.length) { - this.components[index] = value - } else { - throw new Error('changeComponent: index out of bounds!') - } - } - // vector addition - Vector.prototype.add = function (other) { - if (this.size() === other.size()) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] + other.component(i))) - } - return ans - } else { - throw new Error('add: vector must have same size!') - } - } - // vector subtraction - Vector.prototype.sub = function (other) { - if (this.size() === other.size()) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] - other.component(i))) - } - return ans - } else { - throw new Error('add: vector must have same size!') - } - } - // dot-product - Vector.prototype.dot = function (other) { - let sum = 0 - if (other.size() === this.size()) { - const SIZE = other.size() - for (let i = 0; i < SIZE; i++) { - sum += this.components[i] * other.component(i) - } - return sum - } else { - throw new Error('dot: vectors must have same size!') - } - } - // scalar multiplication - Vector.prototype.scalar = function (s) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] * s)) - } - return ans - } - // returns a string representation of this vector. - Vector.prototype.toString = function () { - let ans = '(' - const SIZE = this.components.length - for (let i = 0; i < SIZE; i++) { - if (i < SIZE - 1) { - ans += this.components[i] + ',' - } else { - ans += this.components[i] + ')' - } - } - return ans - } - // converts this vector in a unit basis vector and returns it. - // the One is on position 'pos' - Vector.prototype.createUnitBasis = function (pos) { - if (pos >= 0 && pos < this.components.length) { - for (let i = 0; i < this.components.length; i++) { - if (i === pos) { - this.components[i] = 1.0 - } else { - this.components[i] = 0.0 - } - } - } else { - throw new Error('createUnitBasis: index out of bounds') - } - return this - } - // normalizes this vector and returns it. - Vector.prototype.norm = function () { - const SIZE = this.size() - const quotient = 1.0 / this.eulideanLength() - for (let i = 0; i < SIZE; i++) { - this.components[i] = this.components[i] * quotient - } - return this - } - // returns true if the vectors are equal otherwise false. - Vector.prototype.equal = function (other) { - let ans = true - const SIZE = this.size() - const EPSILON = 0.001 - if (SIZE === other.size()) { - for (let i = 0; i < SIZE; i++) { - if (Math.abs(this.components[i] - other.component(i)) > EPSILON) { - ans = false - } - } - } else { - ans = false - } - return ans - } - return Vector - }()) // end of class Vector - LinearAlgebra.Vector = Vector - // -------------- global functions --------------------------------- - // returns a unit basis vector of size N with a One on position 'pos' - function unitBasisVector (N, pos) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - if (i === pos) { - ans.changeComponent(i, 1.0) - } else { - ans.changeComponent(i, 0) - } - } - return ans - } - LinearAlgebra.unitBasisVector = unitBasisVector - // returns a random vector with integer components (between 'a' and 'b') of size N. - function randomVectorInt (N, a, b) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - ans.changeComponent(i, (Math.floor((Math.random() * b) + a))) - } - return ans - } - LinearAlgebra.randomVectorInt = randomVectorInt - // returns a random vector with floating point components (between 'a' and 'b') of size N. - function randomVectorFloat (N, a, b) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - ans.changeComponent(i, ((Math.random() * b) + a)) - } - return ans - } - LinearAlgebra.randomVectorFloat = randomVectorFloat - // ------------------ end of global functions ----------------------------- - /* - class: Matrix - This class represents a matrix of arbitrary size and operations on it. - */ - const Matrix = /** @class */ (function () { - // constructor for zero-matrix or fix number matrix. - function Matrix (row, col, comps) { - if (comps === undefined) { - comps = [] - } - if (comps.length === 0) { - this.matrix = [] - let rowVector = [] - for (let i = 0; i < row; i++) { - for (let j = 0; j < col; j++) { - rowVector[j] = 0 - } - this.matrix[i] = rowVector - rowVector = [] - } - } else { - this.matrix = comps - } - this.rows = row - this.cols = col - } - // returns the specified component. - Matrix.prototype.component = function (x, y) { - if (x >= 0 && x < this.rows && y >= 0 && y < this.cols) { - return this.matrix[x][y] - } else { - throw new Error('component: index out of bounds') - } - } - // changes the specified component with value 'value'. - Matrix.prototype.changeComponent = function (x, y, value) { - if (x >= 0 && x < this.rows && y >= 0 && y < this.cols) { - this.matrix[x][y] = value - } else { - throw new Error('changeComponent: index out of bounds') - } - } - // returns a string representation of this matrix. - Matrix.prototype.toString = function () { - let ans = '' - for (let i = 0; i < this.rows; i++) { - ans += '|' - for (let j = 0; j < this.cols; j++) { - if (j < this.cols - 1) { - ans += this.matrix[i][j] + ',' - } else { - if (i < this.rows - 1) { - ans += this.matrix[i][j] + '|\n' - } else { - ans += this.matrix[i][j] + '|' - } - } - } - } - return ans - } - // returns the dimension rows x cols as number array - Matrix.prototype.dimension = function () { - const ans = [] - ans[0] = this.rows - ans[1] = this.cols - return ans - } - // matrix addition. returns the result. - Matrix.prototype.add = function (other) { - if (this.rows === other.dimension()[0] && - this.cols === other.dimension()[1]) { - const ans = new Matrix(this.rows, this.cols) - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - ans.changeComponent(i, j, (this.matrix[i][j] + other.component(i, j))) - } - } - return ans - } else { - throw new Error('add: matrices must have same dimension!') - } - } - // returns true if the matrices are equal, otherwise false. - Matrix.prototype.equal = function (other) { - let ans = true - const EPSILON = 0.001 - if (this.rows === other.dimension()[0] && - this.cols === other.dimension()[1]) { - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - if (Math.abs(this.matrix[i][j] - other.component(i, j)) > EPSILON) { - ans = false - } - } - } - } else { - ans = false - } - return ans - } - // matrix-scalar multiplication - Matrix.prototype.scalar = function (c) { - const ans = new Matrix(this.rows, this.cols) - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - ans.changeComponent(i, j, (this.matrix[i][j] * c)) - } - } - return ans - } - return Matrix - }()) // end of class Matrix - LinearAlgebra.Matrix = Matrix -})(LinearAlgebra || (LinearAlgebra = {})) // end of namespace LinearAlgebra - -export { LinearAlgebra } diff --git a/Linear-Algebra/test/test.js b/Linear-Algebra/test/test.js deleted file mode 100644 index a99d97aad9..0000000000 --- a/Linear-Algebra/test/test.js +++ /dev/null @@ -1,213 +0,0 @@ -/* - author: Christian Bender - license: MIT-license - - This file contains the test-suite for the linear algebra library. - The tests use javascript test-framework mocha -*/ - -/* eslint-disable */ - -import { LinearAlgebra } from '../src/la_lib' -import * as assert from 'assert' - -// file is included here -// Tests goes here - -// creating some vectors -describe('Create Vectors', function () { - describe('#toString()', function () { - it('should return a string representation', function () { - assert.strictEqual((new LinearAlgebra.Vector(3, [1, 2, 3])).toString(), '(1,2,3)') - }) - }) - describe('#unitBasisVector()', function () { - it('should return a unit basis vector', function () { - assert.strictEqual(LinearAlgebra.unitBasisVector(3, 1).toString(), '(0,1,0)') - }) - }) -}) - -// operations on it. -describe('Vector operations', function () { - describe('#add()', function () { - it('should return vector (2,4,6)', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual((x.add(y)).toString(), '(2,4,6)') - }) - }) - describe('#sub()', function () { - it('should return vector (0,0,0)', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual((x.sub(y)).toString(), '(0,0,0)') - }) - }) - describe('#dot()', function () { - it('should return the dot-product', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [5, 6, 7]) - assert.strictEqual(x.dot(y), 38) - }) - }) - describe('#scalar()', function () { - it('should return the scalar product', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual(x.scalar(2).toString(), '(2,4,6)') - }) - }) - describe('#norm()', function () { - it('should return the normalizes vector', function () { - var x = new LinearAlgebra.Vector(4, [9, 0, 3, 1]) - var y = x.norm() - assert.ok(Math.abs(y.component(0) - (9.0 / Math.sqrt(91))) <= 0.01) - }) - }) - describe('#eulideanLength()', function () { - it('should return the eulidean length of the vector', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - assert.ok(Math.abs(x.eulideanLength() - 3) <= 0.001) - }) - }) - describe('#size()', function () { - it('should return the size (not eulidean length!) of the vector', function () { - var x = LinearAlgebra.randomVectorInt(10, 1, 5) - assert.strictEqual(x.size(), 10) - }) - }) - describe('#equal()', function () { - it('should compares two vectors', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.ok(x.equal(x)) - assert.ok(!x.equal(y)) - }) - }) -}) - -describe('Methods on vectors', function () { - describe('#component()', function () { - it('should return the specified component', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - assert.strictEqual(x.component(1), 2) - }) - }) - describe('#changeComponent()', function () { - it('should return the changed vector', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - x.changeComponent(1, 5) - assert.strictEqual(x.toString(), '(1,5,2)') - }) - }) - describe('#toString()', function () { - it('should return a string representation of the vector', function () { - var x = new LinearAlgebra.Vector(4, [9, 0, 3, 1]) - assert.strictEqual(x.toString(), '(9,0,3,1)') - }) - }) -}) - -describe('class Matrix', function () { - describe('#component()', function () { - it('should return the specified component', function () { - var A = new LinearAlgebra.Matrix(2, 2) - assert.strictEqual(A.component(0, 1), 0) - var B = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - assert.strictEqual(B.component(1, 0), 3) - }) - }) - describe('#toString()', function () { - it('should return a string representation of the matrix', function () { - var A = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - assert.strictEqual(A.toString(), '|1,2|\n|3,4|') - }) - }) - describe('#dimension()', function () { - it('should return the dimension of the matrix as number array', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - assert.strictEqual(A.dimension()[0], 3) - assert.strictEqual(A.dimension()[1], 2) - }) - }) - describe('#changeComponent()', function () { - it('should change the specified component of the matrix', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - A.changeComponent(1, 0, 5) - assert.strictEqual(A.component(1, 0), 5) - }) - }) - describe('#equal()', function () { - it('should compares the matrices', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var C = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - var D = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [5, 4] - ]) - assert.ok(A.equal(B)) - assert.ok(!A.equal(C)) - assert.ok(!C.equal(D)) - }) - }) - describe('#add()', function () { - it('should return the result of the matrix addition', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var C = A.add(B) - assert.strictEqual(C.component(1, 0), 6) - assert.strictEqual(C.component(1, 1), 8) - assert.strictEqual(C.component(0, 0), 2) - }) - }) - describe('#scalar()', function () { - it('should return the result of the matrix-scalar multiplication', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = A.scalar(2) - var C = new LinearAlgebra.Matrix(3, 2, [ - [2, 4], - [6, 8], - [10, 12] - ]) - assert.ok(B.equal(C)) - }) - }) -}) From 290b2efb52f46ba98579214fe94ea456e8f1580b Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 28 Oct 2021 09:10:04 +0000 Subject: [PATCH 19/62] Auto-update DIRECTORY.md --- DIRECTORY.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 2bf71a6255..e2f2958070 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -135,12 +135,6 @@ * [SHA1](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA1.js) * [SHA256](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA256.js) -## Linear-Algebra - * src - * [la_lib](https://github.com/TheAlgorithms/Javascript/blob/master/Linear-Algebra/src/la_lib.js) - * test - * [test](https://github.com/TheAlgorithms/Javascript/blob/master/Linear-Algebra/test/test.js) - ## Maths * [Abs](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Abs.js) * [AliquotSum](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/AliquotSum.js) From 30abe1a0acb0b1799c78092cf84ded847e4aa03e Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:58:16 +0530 Subject: [PATCH 20/62] chore: fix spelling --- Hashes/SHA256.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Hashes/SHA256.js b/Hashes/SHA256.js index 61841e2abf..d764d31c02 100644 --- a/Hashes/SHA256.js +++ b/Hashes/SHA256.js @@ -45,7 +45,7 @@ function pad (str, bits) { * @return {array} - array of original string split into chunks * * @example - * chunkify("this is a test", 2); // ["th", "is", " i", "s ", "a ", "te", "st"] + * chunkify("this is a test", 2) */ function chunkify (str, size) { const chunks = [] @@ -76,7 +76,7 @@ function rotateRight (bits, turns) { * @return {string} - processed message */ function preProcess (message) { - // covert message to binary representation padded to + // convert message to binary representation padded to // 8 bits, and add 1 let m = message.split('') .map(e => e.charCodeAt(0)) From f8e621988fdd0e4bf26a7be04cc22d2984c7b034 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:59:04 +0530 Subject: [PATCH 21/62] chore: fix spellings --- Hashes/SHA1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hashes/SHA1.js b/Hashes/SHA1.js index 98cb03a444..d56de962f0 100644 --- a/Hashes/SHA1.js +++ b/Hashes/SHA1.js @@ -34,7 +34,7 @@ function pad (str, bits) { * @return {array} - array of original string split into chunks * * @example - * chunkify("this is a test", 2); // ["th", "is", " i", "s ", "a ", "te", "st"] + * chunkify("this is a test", 2) */ function chunkify (str, size) { const chunks = [] From 7722870183ce53ed9d57c633e0aac7bc65200972 Mon Sep 17 00:00:00 2001 From: ggkogkou <76820848+ggkogkou@users.noreply.github.com> Date: Thu, 28 Oct 2021 12:37:07 +0300 Subject: [PATCH 22/62] merge: Created composite Simpson's integration method. Tests included. (#819) * Created composite Simpson's integration method.Tests included * Minor corrections * Auto-update DIRECTORY.md * Styled with standard.js * chore: remove blank line * chore: remove blank line Co-authored-by: ggkogkou Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Rak Laptudirm --- DIRECTORY.md | 1 + Maths/SimpsonIntegration.js | 67 +++++++++++++++++++++++++++ Maths/test/SimpsonIntegration.test.js | 16 +++++++ 3 files changed, 84 insertions(+) create mode 100644 Maths/SimpsonIntegration.js create mode 100644 Maths/test/SimpsonIntegration.test.js diff --git a/DIRECTORY.md b/DIRECTORY.md index 2bf71a6255..4b67c831c7 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -197,6 +197,7 @@ * [ReverseNumber](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/ReverseNumber.js) * [ReversePolishNotation](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/ReversePolishNotation.js) * [SieveOfEratosthenes](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SieveOfEratosthenes.js) + * [SimpsonIntegration](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/SimpsonIntegration.js) * [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) diff --git a/Maths/SimpsonIntegration.js b/Maths/SimpsonIntegration.js new file mode 100644 index 0000000000..32ed9c2114 --- /dev/null +++ b/Maths/SimpsonIntegration.js @@ -0,0 +1,67 @@ +/* +* +* @file +* @title Composite Simpson's rule for definite integral evaluation +* @author: [ggkogkou](https://github.com/ggkogkou) +* @brief Calculate definite integrals using composite Simpson's numerical method +* +* @details The idea is to split the interval in an EVEN number N of intervals and use as interpolation points the xi +* for which it applies that xi = x0 + i*h, where h is a step defined as h = (b-a)/N where a and b are the +* first and last points of the interval of the integration [a, b]. +* +* We create a table of the xi and their corresponding f(xi) values and we evaluate the integral by the formula: +* I = h/3 * {f(x0) + 4*f(x1) + 2*f(x2) + ... + 2*f(xN-2) + 4*f(xN-1) + f(xN)} +* +* That means that the first and last indexed i f(xi) are multiplied by 1, +* the odd indexed f(xi) by 4 and the even by 2. +* +* N must be even number and a= 2') } + + // Check if a < b + if (a > b) { throw Error('a must be less or equal than b') } + if (a === b) return 0 + + // Calculate the step h + const h = (b - a) / N + + // Find interpolation points + let xi = a // initialize xi = x0 + const pointsArray = [] + + // Find the sum {f(x0) + 4*f(x1) + 2*f(x2) + ... + 2*f(xN-2) + 4*f(xN-1) + f(xN)} + let temp + for (let i = 0; i < N + 1; i++) { + if (i === 0 || i === N) temp = func(xi) + else if (i % 2 === 0) temp = 2 * func(xi) + else temp = 4 * func(xi) + + pointsArray.push(temp) + xi += h + } + + // Calculate the integral + let result = h / 3 + temp = 0 + for (let i = 0; i < pointsArray.length; i++) temp += pointsArray[i] + + result *= temp + + if (Number.isNaN(result)) { throw Error('Result is NaN. The input interval doesnt belong to the functions domain') } + + return result +} + +export { integralEvaluation } diff --git a/Maths/test/SimpsonIntegration.test.js b/Maths/test/SimpsonIntegration.test.js new file mode 100644 index 0000000000..c5ebf6a837 --- /dev/null +++ b/Maths/test/SimpsonIntegration.test.js @@ -0,0 +1,16 @@ +import { integralEvaluation } from '../SimpsonIntegration' + +test('Should return the integral of f(x) = sqrt(x) in [1, 3] to be equal 2.797434', () => { + const result = integralEvaluation(16, 1, 3, (x) => { return Math.sqrt(x) }) + expect(Number(result.toPrecision(7))).toBe(2.797434) +}) + +test('Should return the integral of f(x) = sqrt(x) + x^2 in [1, 3] to be equal 11.46410161', () => { + const result = integralEvaluation(64, 1, 3, (x) => { return Math.sqrt(x) + Math.pow(x, 2) }) + expect(Number(result.toPrecision(10))).toBe(11.46410161) +}) + +test('Should return the integral of f(x) = log(x) + Pi*x^3 in [5, 12] to be equal 15809.9141543', () => { + const result = integralEvaluation(128, 5, 12, (x) => { return Math.log(x) + Math.PI * Math.pow(x, 3) }) + expect(Number(result.toPrecision(12))).toBe(15809.9141543) +}) From b1f97477fd19290a2224f5458c8bf4a8ad5b0297 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:08:49 +0530 Subject: [PATCH 23/62] chore: fix spelling --- Maths/MatrixMultiplication.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/MatrixMultiplication.js b/Maths/MatrixMultiplication.js index 9fc2a924bc..739b6b1988 100644 --- a/Maths/MatrixMultiplication.js +++ b/Maths/MatrixMultiplication.js @@ -17,7 +17,7 @@ const matrixCheck = (matrix) => { } } -// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vise versa. +// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vice versa. const twoMatricesCheck = (first, second) => { const [firstRowLength, secondRowLength, firstColLength, secondColLength] = [first.length, second.length, matrixCheck(first), matrixCheck(second)] if (firstRowLength !== secondColLength || secondRowLength !== firstColLength) { From ab00297d40d112e535f00b2e4156d745cd626387 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:09:23 +0530 Subject: [PATCH 24/62] chore: fix spelling --- Maths/SieveOfEratosthenes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/SieveOfEratosthenes.js b/Maths/SieveOfEratosthenes.js index e6e77b2673..01e141f2f0 100644 --- a/Maths/SieveOfEratosthenes.js +++ b/Maths/SieveOfEratosthenes.js @@ -1,7 +1,7 @@ const sieveOfEratosthenes = (n) => { /* * Calculates prime numbers till a number n - * :param n: Number upto which to calculate primes + * :param n: Number up to which to calculate primes * :return: A boolean list containing only primes */ const primes = new Array(n + 1) From 73240043b9a59d67c871d3297a6db3557c4def3f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:10:00 +0530 Subject: [PATCH 25/62] chore: fix spelling --- Maths/FigurateNumber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/FigurateNumber.js b/Maths/FigurateNumber.js index cab8dcefba..058972dee6 100644 --- a/Maths/FigurateNumber.js +++ b/Maths/FigurateNumber.js @@ -1,5 +1,5 @@ /** - Problem Statment and Explanation : + Problem Statement and Explanation : Triangular => https://en.wikipedia.org/wiki/Triangular_number Tetrahedral => https://en.wikipedia.org/wiki/Tetrahedral_number Pentatope => https://en.wikipedia.org/wiki/Pentatope_number From cdb26bfd9cafa66ddc067a0669c1852a69233655 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:10:46 +0530 Subject: [PATCH 26/62] chore: fix spelling --- Maths/BinaryExponentiationIterative.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Maths/BinaryExponentiationIterative.js b/Maths/BinaryExponentiationIterative.js index 705dcded4e..9c1a23f215 100644 --- a/Maths/BinaryExponentiationIterative.js +++ b/Maths/BinaryExponentiationIterative.js @@ -12,13 +12,13 @@ // = exponent(x*x, floor(n/2)) ; if n is odd // = x*exponent(x*x, floor(n/2)) ; if n is even const exponent = (x, n) => { - let ans = 1 + let answer = 1 while (n > 0) { - if (n % 2 !== 0) ans *= x + if (n % 2 !== 0) answer *= x n = Math.floor(n / 2) if (n > 0) x *= x } - return ans + return answer } export { exponent } From a81710899303b52dd65735e3f39dcda2e873338f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:12:30 +0530 Subject: [PATCH 27/62] chore: fix spelling --- Maths/MatrixExponentiationRecursive.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Maths/MatrixExponentiationRecursive.js b/Maths/MatrixExponentiationRecursive.js index b672e69bb0..e86ceebe29 100644 --- a/Maths/MatrixExponentiationRecursive.js +++ b/Maths/MatrixExponentiationRecursive.js @@ -22,27 +22,27 @@ const Identity = (n) => { return res } -const MatMult = (matA, matB) => { - // Input: matA: 2D Array of Numbers of size n x n - // matB: 2D Array of Numbers of size n x n - // Output: matA x matB: 2D Array of Numbers of size n x n +const MatMult = (matrixA, matrixB) => { + // Input: matrixA: 2D Array of Numbers of size n x n + // matrixB: 2D Array of Numbers of size n x n + // Output: matrixA x matrixB: 2D Array of Numbers of size n x n // Complexity: O(n^3) - const n = matA.length - const matC = [] + const n = matrixA.length + const matrixC = [] for (let i = 0; i < n; i++) { - matC[i] = [] + matrixC[i] = [] for (let j = 0; j < n; j++) { - matC[i][j] = 0 + matrixC[i][j] = 0 } } for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { for (let k = 0; k < n; k++) { - matC[i][j] += matA[i][k] * matB[k][j] + matrixC[i][j] += matrixA[i][k] * matrixB[k][j] } } } - return matC + return matrixC } export const MatrixExponentiationRecursive = (mat, m) => { From 75590d697d7e6f42f225cb6bfec0f44f9db949bd Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:39:18 +0530 Subject: [PATCH 28/62] chore: remove codespell from ci --- .github/workflows/ci.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 447eccc501..624b4eac82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,11 +20,4 @@ jobs: - name: 💄 Code style run: npm run style - codespell: - name: Check for spelling errors - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: codespell-project/actions-codespell@master - with: - check_filenames: true + From c2ac3c51ad511e65956db02fede393da817b05b8 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:41:37 +0530 Subject: [PATCH 29/62] feat: add codespell workflow --- .github/workflows/codespell.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/codespell.yml diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 0000000000..ddf345b513 --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,13 @@ +name: codespell +on: [push, pull_request] +jobs: + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: codespell-project/actions-codespell@master + with: + check_filenames: true + skip: *.json,*.yml + From 9d07bdcc3b32bc9edd0b5d81f2617b9c65b97aa3 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:45:01 +0530 Subject: [PATCH 30/62] fix: codespell workflow --- .github/workflows/codespell.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index ddf345b513..4c5e6fd586 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -9,5 +9,6 @@ jobs: - uses: codespell-project/actions-codespell@master with: check_filenames: true - skip: *.json,*.yml + # file types to ignore + skip: "*.json,*.yml" From e75aefe57c9635cb28f71f47004f3efd443dd86b Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:47:35 +0530 Subject: [PATCH 31/62] fix: ignore spellings in directory --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 4c5e6fd586..e96cc46476 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml" + skip: "*.json,*.yml,DIRECTORY.md" From bff45e0f94955512a8332ee01067854867b1df07 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:49:56 +0530 Subject: [PATCH 32/62] chore: fix spellings ./Dynamic-Programming/KadaneAlgo.js:2: contiguos ==> contiguous ./Dynamic-Programming/KadaneAlgo.js:14: posible ==> possible --- Dynamic-Programming/KadaneAlgo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dynamic-Programming/KadaneAlgo.js b/Dynamic-Programming/KadaneAlgo.js index e436b6edd8..a4c423e0f1 100644 --- a/Dynamic-Programming/KadaneAlgo.js +++ b/Dynamic-Programming/KadaneAlgo.js @@ -1,5 +1,5 @@ /* Kadane's algorithm is one of the most efficient ways to - * calculate the maximum contiguos subarray sum for a given array. + * calculate the maximum contiguous subarray sum for a given array. * Below is the implementation of kadanes's algorithm along with * some sample test cases. * There might be a special case in this problem if al the elements @@ -11,7 +11,7 @@ export function kadaneAlgo (array) { let cummulativeSum = 0 - let maxSum = Number.NEGATIVE_INFINITY // maxSum has the least posible value + let maxSum = Number.NEGATIVE_INFINITY // maxSum has the least possible value for (let i = 0; i < array.length; i++) { cummulativeSum = cummulativeSum + array[i] if (maxSum < cummulativeSum) { From c026a65d46bc503a26ca34c0589ff23ce7ece814 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:52:16 +0530 Subject: [PATCH 33/62] chore: fix spelling ./Dynamic-Programming/SieveOfEratosthenes.js:4: upto ==> up to --- Dynamic-Programming/SieveOfEratosthenes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic-Programming/SieveOfEratosthenes.js b/Dynamic-Programming/SieveOfEratosthenes.js index 2203e3fd7f..4fb1b47b52 100644 --- a/Dynamic-Programming/SieveOfEratosthenes.js +++ b/Dynamic-Programming/SieveOfEratosthenes.js @@ -1,7 +1,7 @@ function sieveOfEratosthenes (n) { /* * Calculates prime numbers till a number n - * :param n: Number upto which to calculate primes + * :param n: Number up to which to calculate primes * :return: A boolean list containing only primes */ const primes = new Array(n + 1) From 9d8782a7f60e2ce3a4c0467db091d6c518cb528f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 12:53:59 +0530 Subject: [PATCH 34/62] chore: fix spellings ./Dynamic-Programming/MaxNonAdjacentSum.js:22: Exmaple ==> Example --- Dynamic-Programming/MaxNonAdjacentSum.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic-Programming/MaxNonAdjacentSum.js b/Dynamic-Programming/MaxNonAdjacentSum.js index d1b4c93a8d..e7803b6a23 100644 --- a/Dynamic-Programming/MaxNonAdjacentSum.js +++ b/Dynamic-Programming/MaxNonAdjacentSum.js @@ -19,7 +19,7 @@ function maximumNonAdjacentSum (nums) { return Math.max(maxExcluding, maxIncluding) } -// Exmaple +// Example // maximumNonAdjacentSum([1, 2, 3])) // maximumNonAdjacentSum([1, 5, 3, 7, 2, 2, 6])) From 000551b3177e13dd5dc2f408ef1f56ec78ccec8f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:34:24 +0530 Subject: [PATCH 35/62] chore: fix spelling ./Project-Euler/test/Problem010.test.js:4: upto ==> up to ./Project-Euler/test/Problem010.test.js:8: upto ==> up to ./Project-Euler/test/Problem010.test.js:12: upto ==> up to --- Project-Euler/test/Problem010.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project-Euler/test/Problem010.test.js b/Project-Euler/test/Problem010.test.js index da551e4fa9..2169cabc12 100644 --- a/Project-Euler/test/Problem010.test.js +++ b/Project-Euler/test/Problem010.test.js @@ -1,15 +1,15 @@ import { calculateSumOfPrimeNumbers } from '../Problem010' describe('checkAnagram', () => { - it('Return the sum of prime numbers upto but less than 14', () => { + it('Return the sum of prime numbers up to but less than 14', () => { const SUT = calculateSumOfPrimeNumbers(14) expect(SUT).toBe(41) }) - it('Return the sum of prime numbers upto but less than 10', () => { + it('Return the sum of prime numbers up to but less than 10', () => { const SUT = calculateSumOfPrimeNumbers(10) expect(SUT).toBe(17) }) - it('Return the sum of prime numbers upto but less than 100', () => { + it('Return the sum of prime numbers up to but less than 100', () => { const SUT = calculateSumOfPrimeNumbers(100) expect(SUT).toBe(1060) }) From 72cfef0ed3624f1e5a883cfdc074e73b654f8e16 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:36:11 +0530 Subject: [PATCH 36/62] chore: fix spelling ./String/AlphaNumericPalindrome.js:10: recieves ==> receives ./String/AlphaNumericPalindrome.js:10: sting ==> string ./String/AlphaNumericPalindrome.js:46: varaible ==> variable --- String/AlphaNumericPalindrome.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/String/AlphaNumericPalindrome.js b/String/AlphaNumericPalindrome.js index 2d1a071a29..ee3ca6cbf7 100644 --- a/String/AlphaNumericPalindrome.js +++ b/String/AlphaNumericPalindrome.js @@ -7,7 +7,7 @@ /***************************************************************************** * What is a palindrome? https://en.wikipedia.org/wiki/Palindrome * - * The function alphaNumericPlaindrome() recieves a sting with varying formats + * The function alphaNumericPlaindrome() receives a string with varying formats * like "racecar", "RaceCar", and "race CAR" * The string can also have special characters * like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2" @@ -43,7 +43,7 @@ const alphaNumericPlaindrome = (str) => { // iterate through the arr and check the condition of palindrome for (let i = 0; i < arr.length; i++) { if (arr[i] !== arrRev[arr.length - 1 - i]) { - // if the string is not palindrome then we change palin varaible to 1 + // if the string is not palindrome then we change palin variable to 1 palin = 1 } } From 188c8dadbdb4561b296c9b5f1937bc081206145c Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:37:16 +0530 Subject: [PATCH 37/62] chore: fix spelling ./String/DiceCoefficient.js:3: stings ==> strings --- String/DiceCoefficient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/DiceCoefficient.js b/String/DiceCoefficient.js index ca9471159b..f12bb0cae3 100644 --- a/String/DiceCoefficient.js +++ b/String/DiceCoefficient.js @@ -1,6 +1,6 @@ /* The Sørensen–Dice coefficient is a statistic used to gauge the similarity of two samples. * Applied to strings, it can give you a value between 0 and 1 (included) which tells you how similar they are. - * Dice coefficient is calculated by comparing the bigrams of both stings, + * Dice coefficient is calculated by comparing the bigrams of both strings, * a bigram is a substring of the string of length 2. * read more: https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient */ From 7d82885668cd398c3abd806c6df6a69e776be921 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:38:11 +0530 Subject: [PATCH 38/62] chore: fix spelling ./String/test/DiceCoefficient.test.js:9: atleast ==> at least --- String/test/DiceCoefficient.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/test/DiceCoefficient.test.js b/String/test/DiceCoefficient.test.js index f61f5848ba..cdad3d4c7a 100644 --- a/String/test/DiceCoefficient.test.js +++ b/String/test/DiceCoefficient.test.js @@ -6,7 +6,7 @@ describe('diceCoefficient', () => { expect(diceCoefficient('abc', 'abc')).toBe(1) expect(diceCoefficient('', '')).toBe(1) - // string length needs to be atleast 2 (unless equal) + // string length needs to be at least 2 (unless equal) expect(diceCoefficient('a', '')).toBe(0) expect(diceCoefficient('', 'a')).toBe(0) From 75c537462d8c354ce6607fd2255499c69ecf5a2f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:40:00 +0530 Subject: [PATCH 39/62] chore: fix spelling ./String/test/MaxWord.test.js:8: ba ==> be --- String/test/MaxWord.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/String/test/MaxWord.test.js b/String/test/MaxWord.test.js index 417f1232d5..b2d902c54a 100644 --- a/String/test/MaxWord.test.js +++ b/String/test/MaxWord.test.js @@ -5,8 +5,8 @@ describe('Testing the maxWord function', () => { expect(() => maxWord(10)).toThrow() }) it('get the max word', () => { - const string = 'ba ba ba ba banana' + const string = 'be be be be a a banana' const mostOccurringWord = maxWord(string) - expect(mostOccurringWord).toBe('ba') + expect(mostOccurringWord).toBe('be') }) }) From 5572b3a35274bc5c1f7e8fa17bf37cefec4a52e3 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:42:55 +0530 Subject: [PATCH 40/62] chore: ignore `PermutateString.test.js` --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index e96cc46476..b01ad71ffb 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml,DIRECTORY.md" + skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js" From 997b57627a8ca86a74445f263bb86b06341bd3ed Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:44:07 +0530 Subject: [PATCH 41/62] chore: fix spelling ./String/test/CheckVowels.test.js:62: occurances ==> occurrences --- String/test/CheckVowels.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/String/test/CheckVowels.test.js b/String/test/CheckVowels.test.js index e430fd4a2d..e46cd7de1d 100644 --- a/String/test/CheckVowels.test.js +++ b/String/test/CheckVowels.test.js @@ -59,7 +59,7 @@ describe('Test the checkVowels function', () => { expect(countVowels).toBe(0) }) - it('should count multiple occurances of the same vowel in the input', () => { + it('should count multiple occurrences of the same vowel in the input', () => { const value = 'aaaaa' const countVowels = checkVowels(value) expect(countVowels).toBe(5) From 48f6570cf82bb42cbd90720000217561a8a47f1c Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:54:18 +0530 Subject: [PATCH 42/62] chore: ignore `SubsequenceRecursive.js` --- .github/workflows/codespell.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index b01ad71ffb..e43035867f 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,5 +10,5 @@ jobs: with: check_filenames: true # file types to ignore - skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js" + skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js,SubsequenceRecursive.js" From ee8c54ae3e7c2acfcc5c7d1e4e32380ea6f3462a Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:55:49 +0530 Subject: [PATCH 43/62] chore: fix spelling ./Conversions/TemperatureConversion.js:2: arguement ==> argument --- Conversions/TemperatureConversion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Conversions/TemperatureConversion.js b/Conversions/TemperatureConversion.js index 8bf9130b18..d5b5452f7d 100644 --- a/Conversions/TemperatureConversion.js +++ b/Conversions/TemperatureConversion.js @@ -1,5 +1,5 @@ // This files has functions to convert different temperature units -// Functions take temperature value as a arguement and returns corresponding converted value +// Functions take temperature value as a argument and returns corresponding converted value const celsiusToFahrenheit = (celsius) => { // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius @@ -40,7 +40,7 @@ const fahrenheitToRankine = (fahrenheit) => { const kelvinToCelsius = (kelvin) => { // Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin // Wikipedia reference: https://en.wikipedia.org/wiki/Celsius - return Math.round((kelvin) - 273.15) + return Math.round((kelvin) - 273.15) } const kelvinToFahrenheit = (kelvin) => { From 603bfd4de869f12671a7c851f01fb64031e84239 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 13:56:35 +0530 Subject: [PATCH 44/62] chore: fix spelling ./Conversions/RailwayTimeConversion.js:7: Formate ==> Format ./Conversions/RailwayTimeConversion.js:8: Formate ==> Format --- Conversions/RailwayTimeConversion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Conversions/RailwayTimeConversion.js b/Conversions/RailwayTimeConversion.js index dd06487e13..2537cf4495 100644 --- a/Conversions/RailwayTimeConversion.js +++ b/Conversions/RailwayTimeConversion.js @@ -4,8 +4,8 @@ some changes on hours and minutes and if the time in 'PM' it means the only want some changes in hour value. - Input Formate -> 07:05:45PM - Output Formate -> 19:05:45 + Input Format -> 07:05:45PM + Output Format -> 19:05:45 Problem & Explanation Source : https://www.mathsisfun.com/time.html */ From af09e2c4114ce846e5a6242c156be74d6b2df130 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:39:36 +0530 Subject: [PATCH 45/62] chore: remove Linear Algebra The deleted directory hosted a package which are not accepted by this repository. --- Linear-Algebra/README.md | 114 ----------- Linear-Algebra/package-lock.json | 171 ----------------- Linear-Algebra/package.json | 17 -- Linear-Algebra/src/la_lib.js | 313 ------------------------------- Linear-Algebra/test/test.js | 213 --------------------- 5 files changed, 828 deletions(-) delete mode 100644 Linear-Algebra/README.md delete mode 100644 Linear-Algebra/package-lock.json delete mode 100644 Linear-Algebra/package.json delete mode 100644 Linear-Algebra/src/la_lib.js delete mode 100644 Linear-Algebra/test/test.js diff --git a/Linear-Algebra/README.md b/Linear-Algebra/README.md deleted file mode 100644 index 3f3a922d20..0000000000 --- a/Linear-Algebra/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# Linear algebra library for JavaScript - -This library contains some useful classes and functions for dealing with linear algebra in JavaScript. -The library was orginal written in **TypeScript** and then compiles into pure JavaScript. - ---- - -## Overview - -- class Vector : This class represents a vector of arbitray size and operations on it. - - constructor Vector(N) : creates a zero vector of size N - - constructor Vector(N, components) : creates a vector of size N with the given components. - - createUnitBasis(pos) : converts this vector in a unit basis vector and returns it. - - component(pos) : returns the specified component (indexing at 0) - - changeComponent(pos, value) : change the specified component. - - toString() : returns a string representation of this vector. - - size() : returns the size of the vector. (not the eulidean length!) - - eulideanLength() : computes the eulidean length of this vector. - - add(other) : vector addition, returns the rersult. - - sub(other) : vector subtraction, returns the rersult. - - dot(other) : computes the dot-product and returns it. - - scalar(s) : scalar (s) multiplication. returns the result. - - norm() : normalizes this vector and returns it. - - equal(other) : returns true if the vectors are equal, otherwise false. - -- function unitBasisVector(N,pos) : returns a unit basis vector of size N with a One on position 'pos' -- function randomVectorInt(N,a,b) : returns a random vector with integer components (between 'a' and 'b') of size N. -- function randomVectorFloat(N,a,b) : returns a random vector with floating point components (between 'a' and 'b') of size N. - -- class Matrix : This class represents a matrix of arbitrary size and operations on it. - - constructor(rows, cols) : creates a zero matrix of dimension rows x cols. - - constructor(rows, cols, components) : creates a matrix with fix numbers of dimension rows x cols. - - component(x,y) : returns the specified component. - - changeComponent(x,y,value) : changes the specified component with the new value 'value'. - - toString() : returns a string representation of this matrix. - - dimension() : returns the dimension of this matrix as number arras [rows,cols]. - - add(other) : returns the result of the matrix addition. - - equal(other) : returns true if the matrices are equal, otherwise false. - - scalar(c) : returns the result of the matrix-scalar multiplication. ---- - -## Documentation - -The module is well documented in its source code. Look in the TypeScript file ```la_lib.ts```. - ---- - -## Usage - -You will find the library in the **src** directory its called ```la_lib.js```. You simply need to -include this library in your project **(you don't install anything)**. After that: - -```js - var x = LinearAlgebra.Vector(...); -``` - -The namespace LinearAlgebra contains useful classes and functions for dealing with linear algebra under JavaScript. - -Some examples: - -```js -// ---------------------------- Examples ------------------------------------------ - -// creates vectors -var x = new LinearAlgebra.Vector(5, [1, 2, 3, 4, 5]); -var y = new LinearAlgebra.Vector(5, [1, 2, 3, 4, 5]); - -// prints size of the vector -console.log(x.size()); // ==> 5 - -// changes the 2-th component with 7 -//x.changeComponent(2,7); - -// print the 2-th component. -console.log(x.component(2)); // ==> 3 - -// prints the full vector as string. -console.log(x.toString()); // ==> (1,2,3,4,5) - -// vector addition -console.log(x.add(y).toString()); // ==> (2,3,6,8,10) - -//console.log(x.createUnitBasis(1).toString()); - -// computes the dot-product -console.log(x.dot(y)); // ==> 55 - -// computes and prints the scalar-product -console.log(x.scalar(5).toString()); // ==> (5,10,15,20,25) - -// creates a unit basis vector -console.log(LinearAlgebra.unitBasisVector(3, 0).toString()); // ==> (1,0,0) - -// creates random vectors -console.log(LinearAlgebra.randomVectorInt(3, 0, 5).toString()); -console.log(LinearAlgebra.randomVectorFloat(3, 0, 5).toString()); -``` - ---- - -## Tests - -Go in the directory of the project and type in: -```npm install``` -```npm test``` -The test-suite use the JavaScript test-framework **mocha**. - ---- - -## Contributing - -You can contribute to this project. Feel free and pull request some new features or documention. -**TODO:** Global functions for special matrices. -**TODO:** Documention of the classes and functions. diff --git a/Linear-Algebra/package-lock.json b/Linear-Algebra/package-lock.json deleted file mode 100644 index 1492a09eed..0000000000 --- a/Linear-Algebra/package-lock.json +++ /dev/null @@ -1,171 +0,0 @@ -{ - "name": "linear-algebra-javascript", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "browser-stdout": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", - "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==" - }, - "commander": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "diff": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", - "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==" - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "growl": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", - "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==" - }, - "has-flag": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" - }, - "he": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - } - }, - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "1.1.11" - } - }, - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "requires": { - "minimist": "0.0.8" - } - }, - "mocha": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.2.tgz", - "integrity": "sha512-nmlYKMRpJZLxgzk0bRhcvlpjSisbi0x1JiRl7kctadOMPmecUie7WwCZmcyth+PzX5txKbpcMIvDZCAlx9ISxg==", - "requires": { - "browser-stdout": "1.3.1", - "commander": "2.11.0", - "debug": "3.1.0", - "diff": "3.3.1", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.3", - "he": "1.1.1", - "mkdirp": "0.5.1", - "supports-color": "4.4.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1.0.2" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", - "requires": { - "has-flag": "2.0.0" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - } - } -} diff --git a/Linear-Algebra/package.json b/Linear-Algebra/package.json deleted file mode 100644 index 1631a3f9a7..0000000000 --- a/Linear-Algebra/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "linear-algebra-javascript", - "version": "1.0.0", - "description": "simple linear algebra library for JavaScript", - "main": "index.js", - "directories": { - "test": "test" - }, - "scripts": { - "test": "mocha" - }, - "author": "Christian Bender", - "license": "MIT", - "dependencies": { - "mocha": "^5.0.2" - } -} diff --git a/Linear-Algebra/src/la_lib.js b/Linear-Algebra/src/la_lib.js deleted file mode 100644 index 72d8473e8c..0000000000 --- a/Linear-Algebra/src/la_lib.js +++ /dev/null @@ -1,313 +0,0 @@ -/* - author: Christian Bender - license: MIT-license - - The namespace LinearAlgebra contains useful classes and functions for dealing with - linear algebra under JavaScript. -*/ -let LinearAlgebra; -(function (LinearAlgebra) { - /* - class: Vector - This class represents a vector of arbitrary size and operations on it. - */ - const Vector = /** @class */ (function () { - // constructor - function Vector (N, comps) { - if (comps === undefined) { - comps = [] - } - this.components = new Array(N) - if (comps.length === 0) { - for (let i = 0; i < N; i++) { - this.components[i] = 0.0 - } - } else { - if (N === comps.length) { - this.components = comps - } else { - throw new Error('Vector: invalid size!') - } - } - } // end of constructor - // returns the size of this vector. - // not the eulidean length! - Vector.prototype.size = function () { - return this.components.length - } - // computes the eulidean length. - Vector.prototype.eulideanLength = function () { - let sum = 0 - for (let i = 0; i < this.components.length; i++) { - sum += this.components[i] * this.components[i] - } - return Math.sqrt(sum) - } - // getter for the components of the vector. - // returns a specified component (index) - Vector.prototype.component = function (index) { - return this.components[index] - } - // setter for a specified component of this vector. - Vector.prototype.changeComponent = function (index, value) { - if (index >= 0 && index < this.components.length) { - this.components[index] = value - } else { - throw new Error('changeComponent: index out of bounds!') - } - } - // vector addition - Vector.prototype.add = function (other) { - if (this.size() === other.size()) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] + other.component(i))) - } - return ans - } else { - throw new Error('add: vector must have same size!') - } - } - // vector subtraction - Vector.prototype.sub = function (other) { - if (this.size() === other.size()) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] - other.component(i))) - } - return ans - } else { - throw new Error('add: vector must have same size!') - } - } - // dot-product - Vector.prototype.dot = function (other) { - let sum = 0 - if (other.size() === this.size()) { - const SIZE = other.size() - for (let i = 0; i < SIZE; i++) { - sum += this.components[i] * other.component(i) - } - return sum - } else { - throw new Error('dot: vectors must have same size!') - } - } - // scalar multiplication - Vector.prototype.scalar = function (s) { - const SIZE = this.size() - const ans = new Vector(SIZE) - for (let i = 0; i < SIZE; i++) { - ans.changeComponent(i, (this.components[i] * s)) - } - return ans - } - // returns a string representation of this vector. - Vector.prototype.toString = function () { - let ans = '(' - const SIZE = this.components.length - for (let i = 0; i < SIZE; i++) { - if (i < SIZE - 1) { - ans += this.components[i] + ',' - } else { - ans += this.components[i] + ')' - } - } - return ans - } - // converts this vector in a unit basis vector and returns it. - // the One is on position 'pos' - Vector.prototype.createUnitBasis = function (pos) { - if (pos >= 0 && pos < this.components.length) { - for (let i = 0; i < this.components.length; i++) { - if (i === pos) { - this.components[i] = 1.0 - } else { - this.components[i] = 0.0 - } - } - } else { - throw new Error('createUnitBasis: index out of bounds') - } - return this - } - // normalizes this vector and returns it. - Vector.prototype.norm = function () { - const SIZE = this.size() - const quotient = 1.0 / this.eulideanLength() - for (let i = 0; i < SIZE; i++) { - this.components[i] = this.components[i] * quotient - } - return this - } - // returns true if the vectors are equal otherwise false. - Vector.prototype.equal = function (other) { - let ans = true - const SIZE = this.size() - const EPSILON = 0.001 - if (SIZE === other.size()) { - for (let i = 0; i < SIZE; i++) { - if (Math.abs(this.components[i] - other.component(i)) > EPSILON) { - ans = false - } - } - } else { - ans = false - } - return ans - } - return Vector - }()) // end of class Vector - LinearAlgebra.Vector = Vector - // -------------- global functions --------------------------------- - // returns a unit basis vector of size N with a One on position 'pos' - function unitBasisVector (N, pos) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - if (i === pos) { - ans.changeComponent(i, 1.0) - } else { - ans.changeComponent(i, 0) - } - } - return ans - } - LinearAlgebra.unitBasisVector = unitBasisVector - // returns a random vector with integer components (between 'a' and 'b') of size N. - function randomVectorInt (N, a, b) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - ans.changeComponent(i, (Math.floor((Math.random() * b) + a))) - } - return ans - } - LinearAlgebra.randomVectorInt = randomVectorInt - // returns a random vector with floating point components (between 'a' and 'b') of size N. - function randomVectorFloat (N, a, b) { - const ans = new Vector(N) - for (let i = 0; i < N; i++) { - ans.changeComponent(i, ((Math.random() * b) + a)) - } - return ans - } - LinearAlgebra.randomVectorFloat = randomVectorFloat - // ------------------ end of global functions ----------------------------- - /* - class: Matrix - This class represents a matrix of arbitrary size and operations on it. - */ - const Matrix = /** @class */ (function () { - // constructor for zero-matrix or fix number matrix. - function Matrix (row, col, comps) { - if (comps === undefined) { - comps = [] - } - if (comps.length === 0) { - this.matrix = [] - let rowVector = [] - for (let i = 0; i < row; i++) { - for (let j = 0; j < col; j++) { - rowVector[j] = 0 - } - this.matrix[i] = rowVector - rowVector = [] - } - } else { - this.matrix = comps - } - this.rows = row - this.cols = col - } - // returns the specified component. - Matrix.prototype.component = function (x, y) { - if (x >= 0 && x < this.rows && y >= 0 && y < this.cols) { - return this.matrix[x][y] - } else { - throw new Error('component: index out of bounds') - } - } - // changes the specified component with value 'value'. - Matrix.prototype.changeComponent = function (x, y, value) { - if (x >= 0 && x < this.rows && y >= 0 && y < this.cols) { - this.matrix[x][y] = value - } else { - throw new Error('changeComponent: index out of bounds') - } - } - // returns a string representation of this matrix. - Matrix.prototype.toString = function () { - let ans = '' - for (let i = 0; i < this.rows; i++) { - ans += '|' - for (let j = 0; j < this.cols; j++) { - if (j < this.cols - 1) { - ans += this.matrix[i][j] + ',' - } else { - if (i < this.rows - 1) { - ans += this.matrix[i][j] + '|\n' - } else { - ans += this.matrix[i][j] + '|' - } - } - } - } - return ans - } - // returns the dimension rows x cols as number array - Matrix.prototype.dimension = function () { - const ans = [] - ans[0] = this.rows - ans[1] = this.cols - return ans - } - // matrix addition. returns the result. - Matrix.prototype.add = function (other) { - if (this.rows === other.dimension()[0] && - this.cols === other.dimension()[1]) { - const ans = new Matrix(this.rows, this.cols) - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - ans.changeComponent(i, j, (this.matrix[i][j] + other.component(i, j))) - } - } - return ans - } else { - throw new Error('add: matrices must have same dimension!') - } - } - // returns true if the matrices are equal, otherwise false. - Matrix.prototype.equal = function (other) { - let ans = true - const EPSILON = 0.001 - if (this.rows === other.dimension()[0] && - this.cols === other.dimension()[1]) { - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - if (Math.abs(this.matrix[i][j] - other.component(i, j)) > EPSILON) { - ans = false - } - } - } - } else { - ans = false - } - return ans - } - // matrix-scalar multiplication - Matrix.prototype.scalar = function (c) { - const ans = new Matrix(this.rows, this.cols) - for (let i = 0; i < this.rows; i++) { - for (let j = 0; j < this.cols; j++) { - ans.changeComponent(i, j, (this.matrix[i][j] * c)) - } - } - return ans - } - return Matrix - }()) // end of class Matrix - LinearAlgebra.Matrix = Matrix -})(LinearAlgebra || (LinearAlgebra = {})) // end of namespace LinearAlgebra - -export { LinearAlgebra } diff --git a/Linear-Algebra/test/test.js b/Linear-Algebra/test/test.js deleted file mode 100644 index a99d97aad9..0000000000 --- a/Linear-Algebra/test/test.js +++ /dev/null @@ -1,213 +0,0 @@ -/* - author: Christian Bender - license: MIT-license - - This file contains the test-suite for the linear algebra library. - The tests use javascript test-framework mocha -*/ - -/* eslint-disable */ - -import { LinearAlgebra } from '../src/la_lib' -import * as assert from 'assert' - -// file is included here -// Tests goes here - -// creating some vectors -describe('Create Vectors', function () { - describe('#toString()', function () { - it('should return a string representation', function () { - assert.strictEqual((new LinearAlgebra.Vector(3, [1, 2, 3])).toString(), '(1,2,3)') - }) - }) - describe('#unitBasisVector()', function () { - it('should return a unit basis vector', function () { - assert.strictEqual(LinearAlgebra.unitBasisVector(3, 1).toString(), '(0,1,0)') - }) - }) -}) - -// operations on it. -describe('Vector operations', function () { - describe('#add()', function () { - it('should return vector (2,4,6)', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual((x.add(y)).toString(), '(2,4,6)') - }) - }) - describe('#sub()', function () { - it('should return vector (0,0,0)', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual((x.sub(y)).toString(), '(0,0,0)') - }) - }) - describe('#dot()', function () { - it('should return the dot-product', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - var y = new LinearAlgebra.Vector(3, [5, 6, 7]) - assert.strictEqual(x.dot(y), 38) - }) - }) - describe('#scalar()', function () { - it('should return the scalar product', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.strictEqual(x.scalar(2).toString(), '(2,4,6)') - }) - }) - describe('#norm()', function () { - it('should return the normalizes vector', function () { - var x = new LinearAlgebra.Vector(4, [9, 0, 3, 1]) - var y = x.norm() - assert.ok(Math.abs(y.component(0) - (9.0 / Math.sqrt(91))) <= 0.01) - }) - }) - describe('#eulideanLength()', function () { - it('should return the eulidean length of the vector', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - assert.ok(Math.abs(x.eulideanLength() - 3) <= 0.001) - }) - }) - describe('#size()', function () { - it('should return the size (not eulidean length!) of the vector', function () { - var x = LinearAlgebra.randomVectorInt(10, 1, 5) - assert.strictEqual(x.size(), 10) - }) - }) - describe('#equal()', function () { - it('should compares two vectors', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - var y = new LinearAlgebra.Vector(3, [1, 2, 3]) - assert.ok(x.equal(x)) - assert.ok(!x.equal(y)) - }) - }) -}) - -describe('Methods on vectors', function () { - describe('#component()', function () { - it('should return the specified component', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - assert.strictEqual(x.component(1), 2) - }) - }) - describe('#changeComponent()', function () { - it('should return the changed vector', function () { - var x = new LinearAlgebra.Vector(3, [1, 2, 2]) - x.changeComponent(1, 5) - assert.strictEqual(x.toString(), '(1,5,2)') - }) - }) - describe('#toString()', function () { - it('should return a string representation of the vector', function () { - var x = new LinearAlgebra.Vector(4, [9, 0, 3, 1]) - assert.strictEqual(x.toString(), '(9,0,3,1)') - }) - }) -}) - -describe('class Matrix', function () { - describe('#component()', function () { - it('should return the specified component', function () { - var A = new LinearAlgebra.Matrix(2, 2) - assert.strictEqual(A.component(0, 1), 0) - var B = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - assert.strictEqual(B.component(1, 0), 3) - }) - }) - describe('#toString()', function () { - it('should return a string representation of the matrix', function () { - var A = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - assert.strictEqual(A.toString(), '|1,2|\n|3,4|') - }) - }) - describe('#dimension()', function () { - it('should return the dimension of the matrix as number array', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - assert.strictEqual(A.dimension()[0], 3) - assert.strictEqual(A.dimension()[1], 2) - }) - }) - describe('#changeComponent()', function () { - it('should change the specified component of the matrix', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - A.changeComponent(1, 0, 5) - assert.strictEqual(A.component(1, 0), 5) - }) - }) - describe('#equal()', function () { - it('should compares the matrices', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var C = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [3, 4] - ]) - var D = new LinearAlgebra.Matrix(2, 2, [ - [1, 2], - [5, 4] - ]) - assert.ok(A.equal(B)) - assert.ok(!A.equal(C)) - assert.ok(!C.equal(D)) - }) - }) - describe('#add()', function () { - it('should return the result of the matrix addition', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var C = A.add(B) - assert.strictEqual(C.component(1, 0), 6) - assert.strictEqual(C.component(1, 1), 8) - assert.strictEqual(C.component(0, 0), 2) - }) - }) - describe('#scalar()', function () { - it('should return the result of the matrix-scalar multiplication', function () { - var A = new LinearAlgebra.Matrix(3, 2, [ - [1, 2], - [3, 4], - [5, 6] - ]) - var B = A.scalar(2) - var C = new LinearAlgebra.Matrix(3, 2, [ - [2, 4], - [6, 8], - [10, 12] - ]) - assert.ok(B.equal(C)) - }) - }) -}) From ac0d1b855d39d21f82afe5cece41a330e7242419 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 28 Oct 2021 09:10:04 +0000 Subject: [PATCH 46/62] Auto-update DIRECTORY.md --- DIRECTORY.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4b67c831c7..fdfc8233eb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -135,12 +135,6 @@ * [SHA1](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA1.js) * [SHA256](https://github.com/TheAlgorithms/Javascript/blob/master/Hashes/SHA256.js) -## Linear-Algebra - * src - * [la_lib](https://github.com/TheAlgorithms/Javascript/blob/master/Linear-Algebra/src/la_lib.js) - * test - * [test](https://github.com/TheAlgorithms/Javascript/blob/master/Linear-Algebra/test/test.js) - ## Maths * [Abs](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/Abs.js) * [AliquotSum](https://github.com/TheAlgorithms/Javascript/blob/master/Maths/AliquotSum.js) From 05d944a9b18b5c0c74c409271da22509e3a7cf56 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:58:16 +0530 Subject: [PATCH 47/62] chore: fix spelling --- Hashes/SHA256.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Hashes/SHA256.js b/Hashes/SHA256.js index 61841e2abf..d764d31c02 100644 --- a/Hashes/SHA256.js +++ b/Hashes/SHA256.js @@ -45,7 +45,7 @@ function pad (str, bits) { * @return {array} - array of original string split into chunks * * @example - * chunkify("this is a test", 2); // ["th", "is", " i", "s ", "a ", "te", "st"] + * chunkify("this is a test", 2) */ function chunkify (str, size) { const chunks = [] @@ -76,7 +76,7 @@ function rotateRight (bits, turns) { * @return {string} - processed message */ function preProcess (message) { - // covert message to binary representation padded to + // convert message to binary representation padded to // 8 bits, and add 1 let m = message.split('') .map(e => e.charCodeAt(0)) From a1157e3ff6542a6919c7df352958426dee8ca3bb Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 14:59:04 +0530 Subject: [PATCH 48/62] chore: fix spellings --- Hashes/SHA1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hashes/SHA1.js b/Hashes/SHA1.js index 98cb03a444..d56de962f0 100644 --- a/Hashes/SHA1.js +++ b/Hashes/SHA1.js @@ -34,7 +34,7 @@ function pad (str, bits) { * @return {array} - array of original string split into chunks * * @example - * chunkify("this is a test", 2); // ["th", "is", " i", "s ", "a ", "te", "st"] + * chunkify("this is a test", 2) */ function chunkify (str, size) { const chunks = [] From 0e5268831e9d4a36f7046cfcad2f9e1b6f4c6b20 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:08:49 +0530 Subject: [PATCH 49/62] chore: fix spelling --- Maths/MatrixMultiplication.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/MatrixMultiplication.js b/Maths/MatrixMultiplication.js index 9fc2a924bc..739b6b1988 100644 --- a/Maths/MatrixMultiplication.js +++ b/Maths/MatrixMultiplication.js @@ -17,7 +17,7 @@ const matrixCheck = (matrix) => { } } -// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vise versa. +// tests to see if the matrices have a like side, i.e. the row length on the first matrix matches the column length on the second matrix, or vice versa. const twoMatricesCheck = (first, second) => { const [firstRowLength, secondRowLength, firstColLength, secondColLength] = [first.length, second.length, matrixCheck(first), matrixCheck(second)] if (firstRowLength !== secondColLength || secondRowLength !== firstColLength) { From 9f3e6bc877a05a17441115a23c69543498545409 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:09:23 +0530 Subject: [PATCH 50/62] chore: fix spelling --- Maths/SieveOfEratosthenes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/SieveOfEratosthenes.js b/Maths/SieveOfEratosthenes.js index e6e77b2673..01e141f2f0 100644 --- a/Maths/SieveOfEratosthenes.js +++ b/Maths/SieveOfEratosthenes.js @@ -1,7 +1,7 @@ const sieveOfEratosthenes = (n) => { /* * Calculates prime numbers till a number n - * :param n: Number upto which to calculate primes + * :param n: Number up to which to calculate primes * :return: A boolean list containing only primes */ const primes = new Array(n + 1) From f699ec34b952be73a3d1611bfca2c9e898f1458f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:10:00 +0530 Subject: [PATCH 51/62] chore: fix spelling --- Maths/FigurateNumber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/FigurateNumber.js b/Maths/FigurateNumber.js index cab8dcefba..058972dee6 100644 --- a/Maths/FigurateNumber.js +++ b/Maths/FigurateNumber.js @@ -1,5 +1,5 @@ /** - Problem Statment and Explanation : + Problem Statement and Explanation : Triangular => https://en.wikipedia.org/wiki/Triangular_number Tetrahedral => https://en.wikipedia.org/wiki/Tetrahedral_number Pentatope => https://en.wikipedia.org/wiki/Pentatope_number From 63679bfedbe4974e8a65738f84a53f08588b19e0 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:10:46 +0530 Subject: [PATCH 52/62] chore: fix spelling --- Maths/BinaryExponentiationIterative.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Maths/BinaryExponentiationIterative.js b/Maths/BinaryExponentiationIterative.js index 705dcded4e..9c1a23f215 100644 --- a/Maths/BinaryExponentiationIterative.js +++ b/Maths/BinaryExponentiationIterative.js @@ -12,13 +12,13 @@ // = exponent(x*x, floor(n/2)) ; if n is odd // = x*exponent(x*x, floor(n/2)) ; if n is even const exponent = (x, n) => { - let ans = 1 + let answer = 1 while (n > 0) { - if (n % 2 !== 0) ans *= x + if (n % 2 !== 0) answer *= x n = Math.floor(n / 2) if (n > 0) x *= x } - return ans + return answer } export { exponent } From 25d4455a232530523299635b2c09c35d7b5b101f Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:12:30 +0530 Subject: [PATCH 53/62] chore: fix spelling --- Maths/MatrixExponentiationRecursive.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Maths/MatrixExponentiationRecursive.js b/Maths/MatrixExponentiationRecursive.js index b672e69bb0..e86ceebe29 100644 --- a/Maths/MatrixExponentiationRecursive.js +++ b/Maths/MatrixExponentiationRecursive.js @@ -22,27 +22,27 @@ const Identity = (n) => { return res } -const MatMult = (matA, matB) => { - // Input: matA: 2D Array of Numbers of size n x n - // matB: 2D Array of Numbers of size n x n - // Output: matA x matB: 2D Array of Numbers of size n x n +const MatMult = (matrixA, matrixB) => { + // Input: matrixA: 2D Array of Numbers of size n x n + // matrixB: 2D Array of Numbers of size n x n + // Output: matrixA x matrixB: 2D Array of Numbers of size n x n // Complexity: O(n^3) - const n = matA.length - const matC = [] + const n = matrixA.length + const matrixC = [] for (let i = 0; i < n; i++) { - matC[i] = [] + matrixC[i] = [] for (let j = 0; j < n; j++) { - matC[i][j] = 0 + matrixC[i][j] = 0 } } for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { for (let k = 0; k < n; k++) { - matC[i][j] += matA[i][k] * matB[k][j] + matrixC[i][j] += matrixA[i][k] * matrixB[k][j] } } } - return matC + return matrixC } export const MatrixExponentiationRecursive = (mat, m) => { From a6c81939238d9639afce4e3cf99e97dc643129ad Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:22:08 +0530 Subject: [PATCH 54/62] chore: fix spelling --- Maths/DecimalIsolate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Maths/DecimalIsolate.js b/Maths/DecimalIsolate.js index 06a29fb8ef..ac9f81a076 100644 --- a/Maths/DecimalIsolate.js +++ b/Maths/DecimalIsolate.js @@ -5,6 +5,6 @@ */ export const decimalIsolate = (number) => { - const ans = parseFloat((number + '').replace(/^[-\d]+./, '.')) - return isNaN(ans) === true ? 0 : ans + const answer = parseFloat((number + '').replace(/^[-\d]+./, '.')) + return isNaN(answer) === true ? 0 : answer } From 3b393ad3c9eb107161a2e29403b89b24c3a49bc3 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:23:03 +0530 Subject: [PATCH 55/62] chore: fix spelling --- Data-Structures/Heap/MinPriorityQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data-Structures/Heap/MinPriorityQueue.js b/Data-Structures/Heap/MinPriorityQueue.js index 82de29129b..bc4f26f786 100644 --- a/Data-Structures/Heap/MinPriorityQueue.js +++ b/Data-Structures/Heap/MinPriorityQueue.js @@ -57,7 +57,7 @@ class MinPriorityQueue { output(this.heap.slice(1)) } - // heap reverse can be done by performing swaping the first + // heap reverse can be done by performing swapping the first // element with the last, removing the last element to // new array and calling sink function. heapReverse () { From ce3637a54924b31b0d6de7cfc8751ee9c310012c Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:23:39 +0530 Subject: [PATCH 56/62] chore: fix spelling --- Data-Structures/Array/NumberOfLocalMaximumPoints.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data-Structures/Array/NumberOfLocalMaximumPoints.js b/Data-Structures/Array/NumberOfLocalMaximumPoints.js index a61cd05ac5..0b004f11aa 100644 --- a/Data-Structures/Array/NumberOfLocalMaximumPoints.js +++ b/Data-Structures/Array/NumberOfLocalMaximumPoints.js @@ -2,7 +2,7 @@ * [NumberOfLocalMaximumPoints](https://www.geeksforgeeks.org/find-indices-of-all-local-maxima-and-local-minima-in-an-array/) is an algorithm to find relative bigger numbers compared to their neighbors * * Notes: - * - like the other similar local maxima search function find relative maxima points in array but doesnt stop at one but returns total point count + * - like the other similar local maxima search function find relative maxima points in array but doesn't stop at one but returns total point count * - runs on array A of size n and returns the local maxima count using divide and conquer methodology * * @complexity: O(n) (on average ) From febda87dd7904644553232e2b54d1f65fe1db982 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:25:04 +0530 Subject: [PATCH 57/62] chore: fix spelling --- .../Array/test/NumberOfLocalMaximumPoints.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Data-Structures/Array/test/NumberOfLocalMaximumPoints.test.js b/Data-Structures/Array/test/NumberOfLocalMaximumPoints.test.js index 50edda64b7..41e7b04b52 100644 --- a/Data-Structures/Array/test/NumberOfLocalMaximumPoints.test.js +++ b/Data-Structures/Array/test/NumberOfLocalMaximumPoints.test.js @@ -1,41 +1,41 @@ import { NumberOfLocalMaximumPoints } from '../NumberOfLocalMaximumPoints' describe('LocalMaximomPoint tests', () => { - it('test boundry maximom points - last element', () => { + it('test boundary maximum points - last element', () => { const Array = [1, 2, 3, 4, 5, 6, 12] expect(NumberOfLocalMaximumPoints(Array)).toEqual(1) }) - it('test boundry maximom points - first element', () => { + it('test boundary maximum points - first element', () => { const Array = [13, 6, 5, 4, 3, 2, 1] expect(NumberOfLocalMaximumPoints(Array)).toEqual(1) }) - it('test boundry maximom points - both boundries have maximum points', () => { + it('test boundary maximum points - both boundaries have maximum points', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [13, 2, 3, 4, 5, 6, 12] expect(NumberOfLocalMaximumPoints(Array)).toEqual(2) }) - it('multiple maximom points in the middle', () => { + it('multiple maximum points in the middle', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [1, 3, 2, 5, 6, 9, 2, 7, 12, 1, 0] expect(NumberOfLocalMaximumPoints(Array)).toEqual(3) }) - it('multiple maximom points in the middle with one at end', () => { + it('multiple maximum points in the middle with one at end', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [1, 3, 2, 5, 6, 9, 2, 7, 12, 1, 10] expect(NumberOfLocalMaximumPoints(Array)).toEqual(4) }) - it('multiple maximom points in the middle with one at start', () => { + it('multiple maximum points in the middle with one at start', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [10, 3, 2, 5, 6, 9, 2, 7, 12, 1, 0] expect(NumberOfLocalMaximumPoints(Array)).toEqual(3) }) - it('multiple maximom points in the middle with two more at both ends', () => { + it('multiple maximum points in the middle with two more at both ends', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [10, 3, 11, 5, 6, 9, 2, 7, 12, 1, 10] expect(NumberOfLocalMaximumPoints(Array)).toEqual(5) From 05a052a5c517ff254c4ce95ba364c33d0c7e1fe0 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:26:44 +0530 Subject: [PATCH 58/62] chore: fix spelling --- Data-Structures/Array/test/LocalMaximomPoint.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Data-Structures/Array/test/LocalMaximomPoint.test.js b/Data-Structures/Array/test/LocalMaximomPoint.test.js index e2f1883103..db7d911949 100644 --- a/Data-Structures/Array/test/LocalMaximomPoint.test.js +++ b/Data-Structures/Array/test/LocalMaximomPoint.test.js @@ -1,17 +1,17 @@ import { LocalMaximomPoint } from '../LocalMaximomPoint' -describe('LocalMaximomPoint tests', () => { - it('test boundry maximom points - last element', () => { +describe('LocalMaximumPoint tests', () => { + it('test boundary maximum points - last element', () => { const Array = [1, 2, 3, 4, 5, 6, 12] expect(LocalMaximomPoint(Array)).toEqual(6) }) - it('test boundry maximom points - first element', () => { + it('test boundary maximum points - first element', () => { const Array2 = [13, 6, 5, 4, 3, 2, 1] expect(LocalMaximomPoint(Array2)).toEqual(0) }) - it('test boundry maximom points - should find first maximom point from the top', () => { + it('test boundary maximum points - should find first maximom point from the top', () => { // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [13, 2, 3, 4, 5, 6, 12] expect(LocalMaximomPoint(Array)).toEqual(6) From 1fd6a9b2c2f84b6baf341b773836c95380bc2e43 Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:27:33 +0530 Subject: [PATCH 59/62] chore: fix spelling --- Trees/test/BreadthFirstTreeTraversal.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trees/test/BreadthFirstTreeTraversal.test.js b/Trees/test/BreadthFirstTreeTraversal.test.js index 8b4cae7ead..8e325e02d4 100644 --- a/Trees/test/BreadthFirstTreeTraversal.test.js +++ b/Trees/test/BreadthFirstTreeTraversal.test.js @@ -11,7 +11,7 @@ describe('Breadth First Tree Traversal', () => { root.right.right = new Node(9) binaryTree.root = root - // Vizualization : + // Visualization : // // 7 // / \ From 2689bea5e8e1255f3b4d4e3c3d5af7b23bd7666d Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:28:03 +0530 Subject: [PATCH 60/62] chore: fix spelling --- Backtracking/AllCombinationsOfSizeK.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Backtracking/AllCombinationsOfSizeK.js b/Backtracking/AllCombinationsOfSizeK.js index 547a38c303..c02288d1b6 100644 --- a/Backtracking/AllCombinationsOfSizeK.js +++ b/Backtracking/AllCombinationsOfSizeK.js @@ -2,7 +2,7 @@ Problem: Given two numbers, n and k, make all unique combinations of k numbers from 1 to n and in sorted order What is combinations? - - Combinations is selecting items froms a collections without considering order of selection + - Combinations is selecting items from a collections without considering order of selection Example: - We have an apple, a banana, and a jackfruit From 01a77a4943e29abea14b2556c43f4eee3ceadf2b Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:31:25 +0530 Subject: [PATCH 61/62] chore: fix spelling --- Maths/SimpsonIntegration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/SimpsonIntegration.js b/Maths/SimpsonIntegration.js index 32ed9c2114..b9aa5ade17 100644 --- a/Maths/SimpsonIntegration.js +++ b/Maths/SimpsonIntegration.js @@ -59,7 +59,7 @@ function integralEvaluation (N, a, b, func) { result *= temp - if (Number.isNaN(result)) { throw Error('Result is NaN. The input interval doesnt belong to the functions domain') } + if (Number.isNaN(result)) { throw Error("Result is NaN. The input interval doesn't belong to the functions domain") } return result } From 28d7d82af109b886a9074d9023e4f91b1e8b860b Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Thu, 28 Oct 2021 15:33:35 +0530 Subject: [PATCH 62/62] chore: no need to check filenames --- .github/workflows/codespell.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index e43035867f..0c421e95bc 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -8,7 +8,6 @@ jobs: - uses: actions/checkout@v2 - uses: codespell-project/actions-codespell@master with: - check_filenames: true # file types to ignore skip: "*.json,*.yml,DIRECTORY.md,PermutateString.test.js,SubsequenceRecursive.js"