From 32343b44829f00ba94a9070730dc7ae94113f30b Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 11:59:55 +0800 Subject: [PATCH 01/24] Create codecov.yml --- .github/workflows/codecov.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000000..80056b0d32 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,18 @@ +name: Workflow for Codecov javascript +on: [push, pull_request] +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Node 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm install + - name: Run tests and collect coverage + run: npm run test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 From 3db3879b7ae88c21b54316c605fc2aa7a955f8ae Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 19 Aug 2022 04:00:21 +0000 Subject: [PATCH 02/24] Updated Documentation in README.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index dccfbb7c9a..f2d0bf4fab 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -170,6 +170,7 @@ * [IsEven](Maths/IsEven.js) * [IsOdd](Maths/IsOdd.js) * [IsPronic](Maths/IsPronic.js) + * [JugglerSequence](Maths/JugglerSequence.js) * [LeapYear](Maths/LeapYear.js) * [LinearSieve](Maths/LinearSieve.js) * [LucasSeries](Maths/LucasSeries.js) From fbde08eb447e44bf87399b14e486fdc84c2fbed5 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:08:17 +0800 Subject: [PATCH 03/24] Delete CheckAnagram.js --- String/CheckAnagram.js | 76 ------------------------------------------ 1 file changed, 76 deletions(-) delete mode 100644 String/CheckAnagram.js diff --git a/String/CheckAnagram.js b/String/CheckAnagram.js deleted file mode 100644 index 1fc5854298..0000000000 --- a/String/CheckAnagram.js +++ /dev/null @@ -1,76 +0,0 @@ -// An [Anagram](https://en.wikipedia.org/wiki/Anagram) is a string that is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Anagram check is not case-sensitive; -/** - * @function checkAnagramRegex - * @param {string} str1 - * @param {string} str2 - * @returns {boolean} - * @description - check anagram with the help of Regex - * @example - checkAnagramRegex('node', 'deno') => true - * @example - checkAnagramRegex('Eleven plus two', 'Twelve plus one') => true - */ -const checkAnagramRegex = (str1, str2) => { - // check that inputs are strings. - if (typeof str1 !== 'string' || typeof str2 !== 'string') { - throw new TypeError('Both arguments should be strings.') - } - - // If both strings have not same lengths then they can not be anagram. - if (str1.length !== str2.length) { - return false - } - - /** - * str1 converted to an array and traverse each letter of str1 by reduce method - * reduce method return string which is empty or not. - * if it returns empty string '' -> falsy, with Logical !(NOT) Operator, it's will be converted to boolean and return true else false - */ - return ![...str1].reduce( - (str2Acc, cur) => str2Acc.replace(new RegExp(cur, 'i'), ''), // remove the similar letter from str2Acc in case-insensitive - str2 - ) -} - -/** - * @function checkAnagramMap - * @description - check anagram via using HashMap - * @param {string} str1 - * @param {string} str2 - * @returns {boolean} - * @example - checkAnagramMap('node', 'deno') => true - * @example - checkAnagramMap('Eleven plus two', 'Twelve plus one') => true - */ -const checkAnagramMap = (str1, str2) => { - // check that inputs are strings. - if (typeof str1 !== 'string' || typeof str2 !== 'string') { - throw new TypeError('Both arguments should be strings.') - } - - // If both strings have not same lengths then they can not be anagram. - if (str1.length !== str2.length) { - return false - } - - const str1List = Array.from(str1.toUpperCase()) // str1 to array - - // get the occurrences of str1 characters by using HashMap - const str1Occurs = str1List.reduce( - (map, char) => map.set(char, map.get(char) + 1 || 1), - new Map() - ) - - for (const char of str2.toUpperCase()) { - // if char has not exist to the map it's return false - if (!str1Occurs.has(char)) { - return false - } - - let getCharCount = str1Occurs.get(char) - str1Occurs.set(char, --getCharCount) - - getCharCount === 0 && str1Occurs.delete(char) - } - - return true -} - -export { checkAnagramRegex, checkAnagramMap } From baf9d4b57249d6f161fce422bada92182cf5cb67 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:08:27 +0800 Subject: [PATCH 04/24] Delete CheckAnagram.test.js --- String/test/CheckAnagram.test.js | 181 ------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 String/test/CheckAnagram.test.js diff --git a/String/test/CheckAnagram.test.js b/String/test/CheckAnagram.test.js deleted file mode 100644 index 44adc196bc..0000000000 --- a/String/test/CheckAnagram.test.js +++ /dev/null @@ -1,181 +0,0 @@ -import { checkAnagramMap, checkAnagramRegex } from '../CheckAnagram' - -describe('Testing checkAnagramRegex', () => { - it.each` - inputOne | inputTwo - ${123456} | ${'abcd'} - ${[1, 2, 3, 4, 5, 6]} | ${'abcd'} - ${{ test: 'test' }} | ${'abcd'} - ${'abcd'} | ${123456} - ${'abcd'} | ${[1, 2, 3, 4, 5, 6]} - ${'abcd'} | ${{ test: 'test' }} - `( - 'expects to throw the type Error given values $inputOne and $inputTwo', - ({ inputOne, inputTwo }) => { - expect( - () => checkAnagramRegex(inputOne, inputTwo) - ).toThrowError() - } - ) - - it('expects to return false if the arguments have different lengths', () => { - const SUT = checkAnagramRegex('abs', 'abds') - expect(SUT).toBe(false) - }) - - it('expects to return false if the arguments are not anagrams', () => { - const SUT = checkAnagramRegex('abcs', 'abds') - expect(SUT).toBe(false) - }) - - it('expects to return true if the arguments are anagrams', () => { - const SUT = checkAnagramRegex('abcd', 'bcad') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments of length 1 and are the same letter', () => { - const SUT = checkAnagramRegex('a', 'a') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments of are both empty strings', () => { - const SUT = checkAnagramRegex('', '') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams with an odd length', () => { - const SUT = checkAnagramRegex('abcde', 'edcab') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams with an even length', () => { - const SUT = checkAnagramRegex('abcdef', 'fedcab') - expect(SUT).toBe(true) - }) - - it('expects to return false if either argument is an empty string while the other is not', () => { - const SUT = checkAnagramRegex('', 'edcab') - expect(SUT).toBe(false) - const SUT2 = checkAnagramRegex('edcab', '') - expect(SUT2).toBe(false) - }) - - it('expects to return true if the arguments contain the same letters but have unequal case', () => { - const SUT = checkAnagramRegex('ABDCE', 'abcde') - expect(SUT).toBe(true) - const SUT2 = checkAnagramRegex('AbCdE', 'aBCdE') - expect(SUT2).toBe(true) - const SUT3 = checkAnagramRegex('Eleven plus two', 'Twelve plus one') - expect(SUT3).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain number characters', () => { - const SUT = checkAnagramRegex('a1b2', '12ba') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain space characters', () => { - const SUT = checkAnagramRegex('a1 b2', '1 2ba') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain punctuation characters', () => { - const SUT = checkAnagramRegex('a!1b@2', '1@2ba!') - expect(SUT).toBe(true) - }) - - it('expects to return false if the arguments contain the same letters but contain a different amount of space characters', () => { - const SUT = checkAnagramRegex('ea cb', 'e cba') - expect(SUT).toBe(false) - }) -}) - -describe('Testing checkAnagramMap', () => { - it.each` - inputOne | inputTwo - ${123456} | ${'abcd'} - ${[1, 2, 3, 4, 5, 6]} | ${'abcd'} - ${{ test: 'test' }} | ${'abcd'} - ${'abcd'} | ${123456} - ${'abcd'} | ${[1, 2, 3, 4, 5, 6]} - ${'abcd'} | ${{ test: 'test' }} - `( - 'expects to throw the type Error given values $inputOne and $inputTwo', - ({ inputOne, inputTwo }) => { - expect( - () => checkAnagramMap(inputOne, inputTwo) - ).toThrowError() - } - ) - - it('expects to return false if the arguments have different lengths', () => { - const SUT = checkAnagramMap('abs', 'abds') - expect(SUT).toBe(false) - }) - - it('expects to return false if the arguments are not anagrams', () => { - const SUT = checkAnagramMap('abcs', 'abds') - expect(SUT).toBe(false) - }) - - it('expects to return true if the arguments are anagrams', () => { - const SUT = checkAnagramMap('abcd', 'bcad') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments of length 1 and are the same letter', () => { - const SUT = checkAnagramMap('a', 'a') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments of are both empty strings', () => { - const SUT = checkAnagramMap('', '') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams with an odd length', () => { - const SUT = checkAnagramMap('abcde', 'edcab') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams with an even length', () => { - const SUT = checkAnagramMap('abcdef', 'fedcab') - expect(SUT).toBe(true) - }) - - it('expects to return false if either argument is an empty string while the other is not', () => { - const SUT = checkAnagramMap('', 'edcab') - expect(SUT).toBe(false) - const SUT2 = checkAnagramMap('edcab', '') - expect(SUT2).toBe(false) - }) - - it('expects to return true if the arguments contain the same letters but have unequal case', () => { - const SUT = checkAnagramMap('ABDCE', 'abcde') - expect(SUT).toBe(true) - const SUT2 = checkAnagramMap('AbCdE', 'aBCdE') - expect(SUT2).toBe(true) - const SUT3 = checkAnagramMap('Eleven plus two', 'Twelve plus one') - expect(SUT3).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain number characters', () => { - const SUT = checkAnagramMap('a1b2', '12ba') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain space characters', () => { - const SUT = checkAnagramMap('a1 b2', '1 2ba') - expect(SUT).toBe(true) - }) - - it('expects to return true if the arguments are anagrams and contain punctuation characters', () => { - const SUT = checkAnagramMap('a!1b@2', '1@2ba!') - expect(SUT).toBe(true) - }) - - it('expects to return false if the arguments contain the same letters but contain a different amount of space characters', () => { - const SUT = checkAnagramMap('ea cb', 'e cba') - expect(SUT).toBe(false) - }) -}) From 95cad0166caf23ce32b62c3be7222b061f57f1f8 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:08:44 +0800 Subject: [PATCH 05/24] Delete Pow.js --- Maths/Pow.js | 62 ---------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 Maths/Pow.js diff --git a/Maths/Pow.js b/Maths/Pow.js deleted file mode 100644 index 44ce31e8ac..0000000000 --- a/Maths/Pow.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @function powLinear - * @description - The powLinear function is a power function with Linear O(n) complexity - * @param {number} base - * @param {number} exponent - * @returns {number} - * @example - powLinear(2, 2) => 4 --> 2 * 2 - * @example - powLinear(3, 3) => 27 --> 3 * 3 * 3 - */ -const powLinear = (base, exponent) => { - if (exponent < 0) { - base = 1 / base - exponent = -exponent - } - - let result = 1 - - while (exponent--) { // Break the execution while the exponent will 0 - result *= base - } - - return result -} - -/** - * @function powFaster - * @description - The powFaster function is a power function with O(logN) complexity - * @param {number} base - * @param {number} exponent - * @returns {number} - * @example - powFaster(2, 2) => 4 --> 2 * 2 - * @example - powFaster(3, 3) => 27 --> 3 * 3 * 3 - */ -const powFaster = (base, exponent) => { - if (exponent < 2) { // explanation below - 1 - return base && ([1, base][exponent] || powFaster(1 / base, -exponent)) - } - - if (exponent & 1) { // if the existing exponent is odd - return base * powFaster(base * base, exponent >> 1) // explanation below - 2 - } - - return powFaster(base * base, exponent / 2) -} - -/** - * 1 - Magic of short circuit evaluation (&&, ||) - * if the base is 0 then it returns 0 cause 0 is falsy - * if the base is not 0 then it's must be truthy. after that, it will be executed the right portion of the && (AND) operator - * Now it checks the exponent by the help array index, is it 0 or 1. - * if the exponent is not 0 or 1 it's definitely less than 0, and a negative number is not a valid index number so it returns "undefined" - * if the expression is undefined mean -> falsy, the || (OR) operator evaluates the right portion that is a recursive function. - */ - -/** - * 2 - Play with right shift bitwise operator (>>) - * right shift with any odd numbers it returns the floor number instead of float. - * E.g. if the number is 5, after right shifting with 1 it's will give us 2, not 2.5 - * cause the right shift formula is --> x >> y = |x| / 2^y - */ - -export { powLinear, powFaster } From 4034c0566a3f280f5b772a5fe073cdfb978db56e Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:08:59 +0800 Subject: [PATCH 06/24] Delete Pow.test.js --- Maths/test/Pow.test.js | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 Maths/test/Pow.test.js diff --git a/Maths/test/Pow.test.js b/Maths/test/Pow.test.js deleted file mode 100644 index 9ffb64e52d..0000000000 --- a/Maths/test/Pow.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import { powLinear, powFaster } from '../Pow' - -describe('Testing powLinear function', () => { - it('should return 1 for numbers with exponent 0', () => { - expect(powLinear(2, 0)).toBe(1) - }) - - it('should return 0.5 for numbers with exponent -1', () => { - expect(powLinear(2, -1)).toBe(0.5) - }) - - it('should return 0 for numbers with base 0', () => { - expect(powLinear(0, 23)).toBe(0) - }) - - it('should return the base to the exponent power', () => { - expect(powLinear(24, 4)).toBe(331776) - }) -}) - -describe('Testing powFaster function', () => { - it('should return 1 for numbers with exponent 0', () => { - expect(powFaster(2, 0)).toBe(1) - }) - - it('should return 0.5 for numbers with exponent -1', () => { - expect(powFaster(2, -1)).toBe(0.5) - }) - - it('should return 0 for numbers with base 0', () => { - expect(powFaster(0, 23)).toBe(0) - }) - - it('should return the base to the exponent power', () => { - expect(powFaster(24, 4)).toBe(331776) - }) - - it('should return the result in O(lonN) complexity', () => { - expect(powFaster(2, 64)).toBe(18446744073709552000) // execution time Math.log2(64) -> 6 - }) -}) From 739ae862748e0ec15ffb26b8c391227e18d2f259 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:09:11 +0800 Subject: [PATCH 07/24] Delete PiApproximationMonteCarlo.test.js --- Maths/test/PiApproximationMonteCarlo.test.js | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 Maths/test/PiApproximationMonteCarlo.test.js diff --git a/Maths/test/PiApproximationMonteCarlo.test.js b/Maths/test/PiApproximationMonteCarlo.test.js deleted file mode 100644 index 9727aa5788..0000000000 --- a/Maths/test/PiApproximationMonteCarlo.test.js +++ /dev/null @@ -1,9 +0,0 @@ -import { piEstimation } from '../PiApproximationMonteCarlo' - -describe('PiApproximationMonteCarlo', () => { - it('should be between the range of 2 to 4', () => { - const pi = piEstimation() - const piRange = pi >= 2 && pi <= 4 - expect(piRange).toBeTruthy() - }) -}) From 1fec7b4871cf9610a49526ff0c316c573ce964bf Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:09:34 +0800 Subject: [PATCH 08/24] Delete PiApproximationMonteCarlo.js --- Maths/PiApproximationMonteCarlo.js | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 Maths/PiApproximationMonteCarlo.js diff --git a/Maths/PiApproximationMonteCarlo.js b/Maths/PiApproximationMonteCarlo.js deleted file mode 100644 index 08849b5475..0000000000 --- a/Maths/PiApproximationMonteCarlo.js +++ /dev/null @@ -1,21 +0,0 @@ -// Wikipedia: https://en.wikipedia.org/wiki/Monte_Carlo_method -// Video Explanation: https://www.youtube.com/watch?v=ELetCV_wX_c - -const piEstimation = (iterations = 100000) => { - let circleCounter = 0 - - for (let i = 0; i < iterations; i++) { - // generating random points and checking if it lies within a circle of radius 1 - const x = Math.random() - const y = Math.random() - const radius = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) - - if (radius < 1) circleCounter += 1 - } - - // fomula for pi = (ratio of number inside circle and total iteration) x 4 - const pi = (circleCounter / iterations) * 4 - return pi -} - -export { piEstimation } From 925c5e9411328f72f19aa7ecac9a986e763e4678 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 19 Aug 2022 04:09:56 +0000 Subject: [PATCH 09/24] Updated Documentation in README.md --- DIRECTORY.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index f2d0bf4fab..3aefc962a8 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -187,9 +187,7 @@ * [PerfectNumber](Maths/PerfectNumber.js) * [PerfectSquare](Maths/PerfectSquare.js) * [PermutationAndCombination](Maths/PermutationAndCombination.js) - * [PiApproximationMonteCarlo](Maths/PiApproximationMonteCarlo.js) * [Polynomial](Maths/Polynomial.js) - * [Pow](Maths/Pow.js) * [PowLogarithmic](Maths/PowLogarithmic.js) * [PrimeCheck](Maths/PrimeCheck.js) * [PrimeFactors](Maths/PrimeFactors.js) @@ -285,7 +283,6 @@ * [AlphaNumericPalindrome](String/AlphaNumericPalindrome.js) * [AlternativeStringArrange](String/AlternativeStringArrange.js) * [BoyerMoore](String/BoyerMoore.js) - * [CheckAnagram](String/CheckAnagram.js) * [CheckCamelCase](String/CheckCamelCase.js) * [CheckExceeding](String/CheckExceeding.js) * [CheckFlatCase](String/CheckFlatCase.js) From d222af2c837e381642f17a00f0fc17416f3a8aeb Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:19:18 +0800 Subject: [PATCH 10/24] Create dependabot.yml --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..4872c5afd2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 From 26fc815198b5cd9965b4254c71f8e5aae4d86bb5 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:28:06 +0800 Subject: [PATCH 11/24] Delete dependabot.yml --- .github/dependabot.yml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 4872c5afd2..0000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: 2 -updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 From 26fd2f64eae8c3c05be579dea33b5e7cb4d8c8a7 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:29:18 +0800 Subject: [PATCH 12/24] Create JavascriptAlgoCL.yml --- .github/workflows/JavascriptAlgoCL.yml | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/JavascriptAlgoCL.yml diff --git a/.github/workflows/JavascriptAlgoCL.yml b/.github/workflows/JavascriptAlgoCL.yml new file mode 100644 index 0000000000..3efdca660f --- /dev/null +++ b/.github/workflows/JavascriptAlgoCL.yml @@ -0,0 +1,36 @@ +# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Javascript Algorithm CI + +on: [push, pull_request] + +permissions: write-all + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v2 + + - name: npm install, build, and test + run: | + npm install doctest + npm install standard --save-dev + npx doctest **/*.js || true # TODO: Add all doctests + npx standard + npm ci + npm run build --if-present + + env: + CI: true + + - name: Run the tests + run: npm test -- --coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 From 3af430680c0768f7d93fb51915efb29be6c0d07d Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:29:44 +0800 Subject: [PATCH 13/24] Create codacy-analysis.yaml --- .github/workflows/codacy-analysis.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/codacy-analysis.yaml diff --git a/.github/workflows/codacy-analysis.yaml b/.github/workflows/codacy-analysis.yaml new file mode 100644 index 0000000000..9c7d5fe5a1 --- /dev/null +++ b/.github/workflows/codacy-analysis.yaml @@ -0,0 +1,14 @@ +name: Codacy Analysis CLI + +on: [push, pull_request] + +jobs: + codacy-analysis-cli: + name: Codacy Analysis CLI + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@master From 4d804a3944846118e2e1b231e861d79a32f1872b Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:42:43 +0800 Subject: [PATCH 14/24] Update JavascriptAlgoCL.yml --- .github/workflows/JavascriptAlgoCL.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/JavascriptAlgoCL.yml b/.github/workflows/JavascriptAlgoCL.yml index 3efdca660f..e67ff5bf56 100644 --- a/.github/workflows/JavascriptAlgoCL.yml +++ b/.github/workflows/JavascriptAlgoCL.yml @@ -33,4 +33,4 @@ jobs: run: npm test -- --coverage - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3.1.0 From 77d67b31ba492896642166fe52fa58000d2215df Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 12:46:17 +0800 Subject: [PATCH 15/24] Delete codecov.yml --- .github/workflows/codecov.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100644 index 80056b0d32..0000000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Workflow for Codecov javascript -on: [push, pull_request] -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Node 18 - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Install dependencies - run: npm install - - name: Run tests and collect coverage - run: npm run test - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 From 453ceea33fd52058537ffeb2aef0e7eac0e3ceea Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 13:04:38 +0800 Subject: [PATCH 16/24] Delete AlphaNumericPalindrome.js --- String/AlphaNumericPalindrome.js | 35 -------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 String/AlphaNumericPalindrome.js diff --git a/String/AlphaNumericPalindrome.js b/String/AlphaNumericPalindrome.js deleted file mode 100644 index f3de94b642..0000000000 --- a/String/AlphaNumericPalindrome.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @function alphaNumericPalindrome - * @description alphaNumericPalindrome should return true if the string has alphanumeric characters that are palindrome irrespective of special characters and the letter case. - * @param {string} str the string to check - * @returns {boolean} - * @see [Palindrome](https://en.wikipedia.org/wiki/Palindrome) - * @example - * The function alphaNumericPalindrome() 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" - * - * But the catch is, we have to check only if the alphanumeric characters - * are palindrome i.e remove spaces, symbols, punctuations etc - * and the case of the characters doesn't matter - */ -const alphaNumericPalindrome = (str) => { - if (typeof str !== 'string') { - throw new TypeError('Argument should be string') - } - - // removing all the special characters and turning everything to lowercase - const newStr = str.replace(/[^a-z0-9]+/ig, '').toLowerCase() - const midIndex = newStr.length >> 1 // x >> y = floor(x / 2^y) - - for (let i = 0; i < midIndex; i++) { - if (newStr.at(i) !== newStr.at(~i)) { // ~n = -(n + 1) - return false - } - } - - return true -} - -export default alphaNumericPalindrome From f31b3f0c9b271291bbb86ea4fc54c03b98d1d1b7 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 13:04:46 +0800 Subject: [PATCH 17/24] Delete AlphaNumericPalindrome.test.js --- String/test/AlphaNumericPalindrome.test.js | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 String/test/AlphaNumericPalindrome.test.js diff --git a/String/test/AlphaNumericPalindrome.test.js b/String/test/AlphaNumericPalindrome.test.js deleted file mode 100644 index ab7373b53b..0000000000 --- a/String/test/AlphaNumericPalindrome.test.js +++ /dev/null @@ -1,21 +0,0 @@ -import alphaNumericPalindrome from '../AlphaNumericPalindrome' - -describe('Testing the alpha numeric palindrome', () => { - // should return true if the given string has alphanumeric characters that are palindrome irrespective of case and symbols - it('Testing with valid alphabetic palindrome', () => { - expect(alphaNumericPalindrome('eye')).toBe(true) - expect(alphaNumericPalindrome('Madam')).toBe(true) - expect(alphaNumericPalindrome('race CAR')).toBe(true) - expect(alphaNumericPalindrome('A man, a plan, a canal. Panama')).toBe(true) - }) - - it('Testing with number and symbol', () => { - expect(alphaNumericPalindrome('0_0 (: /-:) 0-0')).toBe(true) - expect(alphaNumericPalindrome('03_|53411435|_30')).toBe(true) - }) - - it('Testing with alphabets and symbols', () => { - expect(alphaNumericPalindrome('five|_/|evif')).toBe(true) - expect(alphaNumericPalindrome('five|_/|four')).toBe(false) - }) -}) From d2bca6db1bad34dcb9cef04f4dfe5f2aa0dbf06f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 19 Aug 2022 05:05:11 +0000 Subject: [PATCH 18/24] Updated Documentation in README.md --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 3aefc962a8..e2a0ed81d7 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -280,7 +280,6 @@ * [TimSort](Sorts/TimSort.js) * [TopologicalSort](Sorts/TopologicalSort.js) * **String** - * [AlphaNumericPalindrome](String/AlphaNumericPalindrome.js) * [AlternativeStringArrange](String/AlternativeStringArrange.js) * [BoyerMoore](String/BoyerMoore.js) * [CheckCamelCase](String/CheckCamelCase.js) From 8b0243794d7dc1ca9620e29d81c9f848eb009138 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 22:17:01 +0800 Subject: [PATCH 19/24] Delete CollatzSequence.js --- Maths/CollatzSequence.js | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 Maths/CollatzSequence.js diff --git a/Maths/CollatzSequence.js b/Maths/CollatzSequence.js deleted file mode 100644 index d8ead61cc2..0000000000 --- a/Maths/CollatzSequence.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @function collatz - * @description Applies the Collatz Sequence on a specified number. - * The Collatz Sequence states that every natural number will always fall in a 1, 2, 4 loop when iterated under the following function: - * If the number is even, divide by 2, and if its odd, multiply it by 3 and add 1. - * - * @parama {Integer} n The number to apply the Collatz Sequence to. - * - * @return An array of steps and the final result.. - * - * @see [Collatz Conjecture](https://en.wikipedia.org/wiki/Collatz_conjecture) - * - * @example collatz(1) = { result: 1, steps: [] } - * @example collatz(5) = { result: 1, steps: [16, 8, 4, 2, 1] } -*/ -export function collatz (n) { - const steps = [] - - while (n !== 1) { - if (n % 2 === 0) { - n = n / 2 - } else { - n = 3 * n + 1 - } - - steps.push(n) - } - - return { result: n, steps: steps } -} From 70380054ddbfe60292261e85c48b701396424192 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 22:17:12 +0800 Subject: [PATCH 20/24] Delete CollatzSequence.test.js --- Maths/test/CollatzSequence.test.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Maths/test/CollatzSequence.test.js diff --git a/Maths/test/CollatzSequence.test.js b/Maths/test/CollatzSequence.test.js deleted file mode 100644 index f837bd90d7..0000000000 --- a/Maths/test/CollatzSequence.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { collatz } from '../CollatzSequence' - -describe('The Collatz Sequence', () => { - it('Should be 1', () => { - expect(collatz(1)).toStrictEqual({ result: 1, steps: [] }) - expect(collatz(5)).toStrictEqual({ result: 1, steps: [16, 8, 4, 2, 1] }) - }) -}) From c33c260866112bd634a8d51798b4cd30712721de Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 22:19:35 +0800 Subject: [PATCH 21/24] Delete JugglerSequence.js --- Maths/JugglerSequence.js | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 Maths/JugglerSequence.js diff --git a/Maths/JugglerSequence.js b/Maths/JugglerSequence.js deleted file mode 100644 index 96a2a35150..0000000000 --- a/Maths/JugglerSequence.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Juggler Sequence: https://en.wikipedia.org/wiki/Juggler_sequence - * function jugglerSequence - * Juggler Sequence is a series of integer number in which the first term starts with a positive integer number n - * and the remaining terms are generated from the immediate previous term using the recurrence relation - * Produce Juggler Sequence using number n as the first term of the sequence and store in an array - * Reference: https://www.geeksforgeeks.org/juggler-sequence/ - * jugglerSequence(3) // returns [3, 5, 11, 36, 6, 2, 1 ] - * jugglerSequence(9) // returns [9, 27, 140, 11, 36, 6, 2, 1] - * jugglerSequence(15) // returns [15, 58, 7, 18, 4, 2, 1] - */ - -function jugglerSequence (n) { - const sequence = [] - sequence.push(n) - // Calculate terms until last term is not 1 - while (n !== 1) { - n = Math.floor(n ** ((n % 2) + 0.5)) - sequence.push(n) - } - return sequence -} - -export { jugglerSequence } From 613710ccae36d000ba46d58a489e60f78675ebd2 Mon Sep 17 00:00:00 2001 From: tehliang Date: Fri, 19 Aug 2022 22:19:47 +0800 Subject: [PATCH 22/24] Delete JugglerSequence.test.js --- Maths/test/JugglerSequence.test.js | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 Maths/test/JugglerSequence.test.js diff --git a/Maths/test/JugglerSequence.test.js b/Maths/test/JugglerSequence.test.js deleted file mode 100644 index 392047a95b..0000000000 --- a/Maths/test/JugglerSequence.test.js +++ /dev/null @@ -1,21 +0,0 @@ -import { jugglerSequence } from '../JugglerSequence' - -describe('Testing jugglerSequence function', () => { - it('should return [3, 5, 11, 36, 6, 2, 1 ] if the number is 3', () => { - expect(jugglerSequence(3)).toEqual( - expect.arrayContaining([3, 5, 11, 36, 6, 2, 1]) - ) - }) - - it('should return [9, 27, 140, 11, 36, 6, 2, 1] if the number is 9', () => { - expect(jugglerSequence(9)).toEqual( - expect.arrayContaining([9, 27, 140, 11, 36, 6, 2, 1]) - ) - }) - - it('should return [15, 58, 7, 18, 4, 2, 1] if the number is 15', () => { - expect(jugglerSequence(15)).toEqual( - expect.arrayContaining([15, 58, 7, 18, 4, 2, 1]) - ) - }) -}) From 8134ca1a909ea3d8b3881353705dc0dffb555b2a Mon Sep 17 00:00:00 2001 From: tehliang Date: Mon, 22 Aug 2022 13:57:48 +0800 Subject: [PATCH 23/24] Delete LeapYear.js --- Maths/LeapYear.js | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 Maths/LeapYear.js diff --git a/Maths/LeapYear.js b/Maths/LeapYear.js deleted file mode 100644 index bddcea7afc..0000000000 --- a/Maths/LeapYear.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * isLeapYear :: Number -> Boolean - * - * Check if a year is a leap year or not. A leap year is a year which has 366 days. - * For the extra +1 day the February month contains 29 days instead of 28 days. - * - * The logic behind the leap year is- - * 1. If the year is divisible by 400 then it is a leap year. - * 2. If it is not divisible by 400 but divisible by 100 then it is not a leap year. - * 3. If the year is not divisible by both 400 and 100 but divisible by 4 then a leap year. - * 4. Other cases except the describing ones are not a leap year. - * - * @param {number} year - * @returns {boolean} true if this is a leap year, false otherwise. - */ -export const isLeapYear = (year) => { - if (year % 400 === 0) return true - if (year % 100 === 0) return false - if (year % 4 === 0) return true - - return false -} From 74d136b748ec80a638f96c88a9b046659f0545a7 Mon Sep 17 00:00:00 2001 From: tehliang Date: Mon, 22 Aug 2022 13:58:01 +0800 Subject: [PATCH 24/24] Delete LeapYear.test.js --- Maths/test/LeapYear.test.js | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 Maths/test/LeapYear.test.js diff --git a/Maths/test/LeapYear.test.js b/Maths/test/LeapYear.test.js deleted file mode 100644 index c30786c0e1..0000000000 --- a/Maths/test/LeapYear.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { isLeapYear } from '../LeapYear' - -describe('Leap Year', () => { - it('Should return true on the year 2000', () => { - expect(isLeapYear(2000)).toBe(true) - }) - it('Should return false on the year 2001', () => { - expect(isLeapYear(2001)).toBe(false) - }) - it('Should return false on the year 2002', () => { - expect(isLeapYear(2002)).toBe(false) - }) - it('Should return false on the year 2003', () => { - expect(isLeapYear(2003)).toBe(false) - }) - it('Should return false on the year 2004', () => { - expect(isLeapYear(2004)).toBe(true) - }) - it('Should return false on the year 1900', () => { - expect(isLeapYear(1900)).toBe(false) - }) -}) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy