From 23ec55cb125102728283f4d0b2085f5c948869b0 Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Mon, 28 Nov 2022 08:54:56 +0530 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20added=20hexagonal=20numbers=20?= =?UTF-8?q?=F0=9F=93=8F=E2=9C=8F=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Maths/Series/HexagonalNumbers.ts | 27 ++++++++++++++++++++++ Maths/Series/test/HexagonalNumbers.test.ts | 15 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 Maths/Series/HexagonalNumbers.ts create mode 100644 Maths/Series/test/HexagonalNumbers.test.ts diff --git a/Maths/Series/HexagonalNumbers.ts b/Maths/Series/HexagonalNumbers.ts new file mode 100644 index 00000000..d0856fc2 --- /dev/null +++ b/Maths/Series/HexagonalNumbers.ts @@ -0,0 +1,27 @@ +/** + * @function HexagonalNumbers + * @description To generate the requested number of hexagonal numbers + * @summary A hexagonal number, hₙ, is a figurate number which represents the number + * of distinct dots in a pattern of dots consisting of the outlines of regular + * hexagons with sides upto 'n' dots, when the hexagons are overlaid so that they share a common vertex + * + * The nth hexagonal number, hₙ, is calculated by the formula: + * hₙ = n * (2n - 1) + * @see [Wikipedia](https://en.wikipedia.org/wiki/Hexagonal_number) + * @see [OEIS](https://oeis.org/A000384) + * @param {number} n - The number of Hexagonal numbers to generate + * @returns {number[]} - An array containing first 'n' hexagonal numbers + * @example HexagonalNumbers(10) = [ 1, 6, 15, 28, 45, 66, 91, 120, 153, 190 ] + * @example HexagonalNumbers(15) = [ 1, 6, 15, 28, 45, 66, 91, 120, 153, 190, 231, 276, 325, 378, 435 ] + */ +export const HexagonalNumbers = (n: number): number[] => { + if (isNaN(n)) throw new Error('The input needs to be a number') + if (!Number.isInteger(n) || n < 0) throw new Error('The input needs to be a non-negative integer') + const hexagonalNumbers = [] + + for (let i = 1; i <= n; i++) { + hexagonalNumbers.push(i * (2 * i - 1)) + } + + return hexagonalNumbers +} diff --git a/Maths/Series/test/HexagonalNumbers.test.ts b/Maths/Series/test/HexagonalNumbers.test.ts new file mode 100644 index 00000000..454b7d25 --- /dev/null +++ b/Maths/Series/test/HexagonalNumbers.test.ts @@ -0,0 +1,15 @@ +import { HexagonalNumbers } from "../HexagonalNumbers"; + +describe("HexagonalNumbers", () => { + it("should return the first 10 hexagonal numbers", () => { + expect(HexagonalNumbers(10)).toStrictEqual([1, 6, 15, 28, 45, 66, 91, 120, 153, 190]); + }) + + it("should return the first 5 hexagonal numbers", () => { + expect(HexagonalNumbers(5)).toStrictEqual([1, 6, 15, 28, 45]) + }) + + it("should return zero hexagonal numbers", () => { + expect(HexagonalNumbers(0)).toStrictEqual([]) + }) +}) \ No newline at end of file From 4d02bd0b4bbb55157b791163dfb21c2977c22069 Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Mon, 28 Nov 2022 11:44:22 +0530 Subject: [PATCH 2/8] When tf did it become lowercase directories AYO --- {Maths/Series => maths/series}/HexagonalNumbers.ts | 0 {Maths/Series => maths/series}/test/HexagonalNumbers.test.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {Maths/Series => maths/series}/HexagonalNumbers.ts (100%) rename {Maths/Series => maths/series}/test/HexagonalNumbers.test.ts (100%) diff --git a/Maths/Series/HexagonalNumbers.ts b/maths/series/HexagonalNumbers.ts similarity index 100% rename from Maths/Series/HexagonalNumbers.ts rename to maths/series/HexagonalNumbers.ts diff --git a/Maths/Series/test/HexagonalNumbers.test.ts b/maths/series/test/HexagonalNumbers.test.ts similarity index 100% rename from Maths/Series/test/HexagonalNumbers.test.ts rename to maths/series/test/HexagonalNumbers.test.ts From 614df1886ee007962f2c626a83a2d157139f6a7c Mon Sep 17 00:00:00 2001 From: autoprettier Date: Mon, 28 Nov 2022 06:14:36 +0000 Subject: [PATCH 3/8] Formatting filenames 4d02bd0b --- maths/series/{HexagonalNumbers.ts => hexagonalnumbers.ts} | 0 .../test/{HexagonalNumbers.test.ts => hexagonalnumbers.test.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename maths/series/{HexagonalNumbers.ts => hexagonalnumbers.ts} (100%) rename maths/series/test/{HexagonalNumbers.test.ts => hexagonalnumbers.test.ts} (100%) diff --git a/maths/series/HexagonalNumbers.ts b/maths/series/hexagonalnumbers.ts similarity index 100% rename from maths/series/HexagonalNumbers.ts rename to maths/series/hexagonalnumbers.ts diff --git a/maths/series/test/HexagonalNumbers.test.ts b/maths/series/test/hexagonalnumbers.test.ts similarity index 100% rename from maths/series/test/HexagonalNumbers.test.ts rename to maths/series/test/hexagonalnumbers.test.ts From 6084ad4cc26d6d9b3087152e00b193598aae6376 Mon Sep 17 00:00:00 2001 From: autoprettier Date: Mon, 28 Nov 2022 06:14:36 +0000 Subject: [PATCH 4/8] Update DIRECTORY.md --- DIRECTORY.md | 67 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 53d56eaf..1e2be2a2 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,41 +1,50 @@ ## Ciphers - * [Xor Cipher](https://github.com/TheAlgorithms/TypeScript/blob/master/ciphers/xor_cipher.ts) + * [Xor Cipher](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/ciphers/xor_cipher.ts) ## Data Structures - * [Stack](https://github.com/TheAlgorithms/TypeScript/blob/master/data_structures/stack.ts) + * [Stack](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/stack.ts) ## Dynamic Programming - * [Knapsack](https://github.com/TheAlgorithms/TypeScript/blob/master/dynamic_programming/knapsack.ts) + * [Knapsack](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/dynamic_programming/knapsack.ts) ## Maths - * [Absolute Value](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/absolute_value.ts) - * [Aliquot Sum](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/aliquot_sum.ts) - * [Armstrong Number](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/armstrong_number.ts) - * [Binary Convert](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/binary_convert.ts) - * [Calculate Mean](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/calculate_mean.ts) - * [Degrees To Radians](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/degrees_to_radians.ts) - * [Digit Sum](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/digit_sum.ts) - * [Factorial](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/factorial.ts) - * [Fibonacci](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/fibonacci.ts) - * [Find Min](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/find_min.ts) - * [Greatest Common Factor](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/greatest_common_factor.ts) - * [Is Divisible](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/is_divisible.ts) - * [Is Even](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/is_even.ts) - * [Is Leap Year](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/is_leap_year.ts) - * [Is Odd](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/is_odd.ts) - * [Lowest Common Multiple](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/lowest_common_multiple.ts) - * [Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/perfect_square.ts) - * [Radians To Degrees](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/radians_to_degrees.ts) - * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/TypeScript/blob/master/maths/sieve_of_eratosthenes.ts) + * [Absolute Value](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/absolute_value.ts) + * [Aliquot Sum](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/aliquot_sum.ts) + * [Armstrong Number](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/armstrong_number.ts) + * [Binary Convert](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/binary_convert.ts) + * [Calculate Mean](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/calculate_mean.ts) + * [Degrees To Radians](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/degrees_to_radians.ts) + * [Digit Sum](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/digit_sum.ts) + * [Factorial](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/factorial.ts) + * [Fibonacci](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/fibonacci.ts) + * [Find Min](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/find_min.ts) + * [Greatest Common Factor](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/greatest_common_factor.ts) + * [Is Divisible](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/is_divisible.ts) + * [Is Even](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/is_even.ts) + * [Is Leap Year](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/is_leap_year.ts) + * [Is Odd](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/is_odd.ts) + * [Lowest Common Multiple](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/lowest_common_multiple.ts) + * [Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_square.ts) + * [Radians To Degrees](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/radians_to_degrees.ts) + * Series + * [Hexagonalnumbers](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/hexagonalnumbers.ts) + * Test + * [Hexagonalnumbers.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/test/hexagonalnumbers.test.ts) + * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/sieve_of_eratosthenes.ts) + +## Other + * [Parse Nested Brackets](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/parse_nested_brackets.ts) + * Test + * [Parse Nested Brackets.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/other/test/parse_nested_brackets.test.ts) ## Search - * [Binary Search](https://github.com/TheAlgorithms/TypeScript/blob/master/search/binary_search.ts) - * [Linear Search](https://github.com/TheAlgorithms/TypeScript/blob/master/search/linear_search.ts) + * [Binary Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/binary_search.ts) + * [Linear Search](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/search/linear_search.ts) ## Sorts - * [Bubble Sort](https://github.com/TheAlgorithms/TypeScript/blob/master/sorts/bubble_sort.ts) - * [Gnome Sort](https://github.com/TheAlgorithms/TypeScript/blob/master/sorts/gnome_sort.ts) - * [Insertion Sort](https://github.com/TheAlgorithms/TypeScript/blob/master/sorts/insertion_sort.ts) - * [Merge Sort](https://github.com/TheAlgorithms/TypeScript/blob/master/sorts/merge_sort.ts) - * [Quick Sort](https://github.com/TheAlgorithms/TypeScript/blob/master/sorts/quick_sort.ts) + * [Bubble Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/bubble_sort.ts) + * [Gnome Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/gnome_sort.ts) + * [Insertion Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/insertion_sort.ts) + * [Merge Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/merge_sort.ts) + * [Quick Sort](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/sorts/quick_sort.ts) From 050ce7ea1dd07a2db8e684663db107f411d1ea58 Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Mon, 28 Nov 2022 11:47:30 +0530 Subject: [PATCH 5/8] fix to follow new filename guidelines --- maths/series/{hexagonalnumbers.ts => hexagonal_numbers.ts} | 0 .../test/{hexagonalnumbers.test.ts => hexagonal_numbers.test.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename maths/series/{hexagonalnumbers.ts => hexagonal_numbers.ts} (100%) rename maths/series/test/{hexagonalnumbers.test.ts => hexagonal_numbers.test.ts} (100%) diff --git a/maths/series/hexagonalnumbers.ts b/maths/series/hexagonal_numbers.ts similarity index 100% rename from maths/series/hexagonalnumbers.ts rename to maths/series/hexagonal_numbers.ts diff --git a/maths/series/test/hexagonalnumbers.test.ts b/maths/series/test/hexagonal_numbers.test.ts similarity index 100% rename from maths/series/test/hexagonalnumbers.test.ts rename to maths/series/test/hexagonal_numbers.test.ts From 0b3ca559bdb140ebc7c0d8814f0e86fe9da763c1 Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Mon, 28 Nov 2022 17:35:11 +0530 Subject: [PATCH 6/8] =?UTF-8?q?Fix=20imports,=20new=20rules=20making=20lif?= =?UTF-8?q?e=20hard=20ffs=F0=9F=92=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maths/series/test/hexagonal_numbers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/series/test/hexagonal_numbers.test.ts b/maths/series/test/hexagonal_numbers.test.ts index 454b7d25..27f0eda2 100644 --- a/maths/series/test/hexagonal_numbers.test.ts +++ b/maths/series/test/hexagonal_numbers.test.ts @@ -1,4 +1,4 @@ -import { HexagonalNumbers } from "../HexagonalNumbers"; +import { HexagonalNumbers } from "../hexagonal_numbers"; describe("HexagonalNumbers", () => { it("should return the first 10 hexagonal numbers", () => { From 71206e5ab676937c6dfbfa2319e7d79304a7f05d Mon Sep 17 00:00:00 2001 From: autoprettier Date: Mon, 28 Nov 2022 12:13:53 +0000 Subject: [PATCH 7/8] Update DIRECTORY.md --- DIRECTORY.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 1e2be2a2..1d94594b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -28,9 +28,9 @@ * [Perfect Square](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/perfect_square.ts) * [Radians To Degrees](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/radians_to_degrees.ts) * Series - * [Hexagonalnumbers](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/hexagonalnumbers.ts) + * [Hexagonal Numbers](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/hexagonal_numbers.ts) * Test - * [Hexagonalnumbers.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/test/hexagonalnumbers.test.ts) + * [Hexagonal Numbers.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/series/test/hexagonal_numbers.test.ts) * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/maths/sieve_of_eratosthenes.ts) ## Other From 493bdf682065e5f4ac2fb440c798fdd6ab7d16b5 Mon Sep 17 00:00:00 2001 From: SpiderMath <71999854+SpiderMath@users.noreply.github.com> Date: Thu, 1 Dec 2022 16:19:31 +0530 Subject: [PATCH 8/8] add empty line at the end --- maths/series/test/hexagonal_numbers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/series/test/hexagonal_numbers.test.ts b/maths/series/test/hexagonal_numbers.test.ts index 27f0eda2..f06467f9 100644 --- a/maths/series/test/hexagonal_numbers.test.ts +++ b/maths/series/test/hexagonal_numbers.test.ts @@ -12,4 +12,4 @@ describe("HexagonalNumbers", () => { it("should return zero hexagonal numbers", () => { expect(HexagonalNumbers(0)).toStrictEqual([]) }) -}) \ No newline at end of file +})