Skip to content

Commit c9b3d38

Browse files
authored
chore: fix naming convention for maths functions (TheAlgorithms#209)
* chore: added function return type * chore: fix naming conventions for maths functions
1 parent 2e4d806 commit c9b3d38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+199
-199
lines changed

maths/absolute_value.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* @function AbsoluteValue
2+
* @function absoluteValue
33
* @description Calculate the absolute value of an input number.
44
* @param {number} number - a numeric input value
55
* @return {number} - Absolute number of input number
66
* @see https://en.wikipedia.org/wiki/Absolute_value
7-
* @example AbsoluteValue(-10) = 10
8-
* @example AbsoluteValue(50) = 50
9-
* @example AbsoluteValue(0) = 0
7+
* @example absoluteValue(-10) = 10
8+
* @example absoluteValue(50) = 50
9+
* @example absoluteValue(0) = 0
1010
*/
1111

12-
export const AbsoluteValue = (number: number): number => {
12+
export const absoluteValue = (number: number): number => {
1313
// if input number is less than 0, convert it to positive via double negation
1414
// e.g. if n = -2, then return -(-2) = 2
1515
return number < 0 ? -number : number;

maths/aliquot_sum.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function AliquotSum
2+
* @function aliquotSum
33
* @description Returns the aliquot sum of the provided number
44
* @summary The aliquot sum of a number n is the sum of all the proper divisors
55
* of n apart from n itself.
@@ -9,10 +9,10 @@
99
* @param {number} num The input number
1010
* @return {number} The aliquot sum of the number
1111
* @see [Wikipedia](https://en.wikipedia.org/wiki/Aliquot_sum)
12-
* @example AliquotSum(18) = 21
13-
* @example AliquotSum(15) = 9
12+
* @example aliquotSum(18) = 21
13+
* @example aliquotSum(15) = 9
1414
*/
15-
export const AliquotSum = (num: number): number => {
15+
export const aliquotSum = (num: number): number => {
1616
if (typeof num !== 'number') throw new TypeError('Input needs to be a number')
1717
if (num < 0) throw new TypeError('Input cannot be negative')
1818
if (!Number.isInteger(num)) throw new TypeError('Input cannot be a decimal')

maths/armstrong_number.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function ArmstrongNumber
2+
* @function armstrongNumber
33
* @description Check if the provided number is an Armstrong number or not.
44
* @summary Armstrong numbers are numbers, the sum of whose digits each raised
55
* to the power of the number of digits is equal to the number itself.
@@ -10,10 +10,10 @@
1010
* @return {boolean} Whether the input number is an Armstrong number
1111
* @see [Wikipedia](https://en.wikipedia.org/wiki/Armstrong_number)
1212
* @see [OEIS](https://oeis.org/A005188)
13-
* @example ArmstrongNumber(370) = true
14-
* @example ArmstrongNumber(10) = false
13+
* @example armstrongNumber(370) = true
14+
* @example armstrongNumber(10) = false
1515
*/
16-
export const ArmstrongNumber = (num: number): boolean => {
16+
export const armstrongNumber = (num: number): boolean => {
1717
if (typeof num !== 'number' || num <= 0) return false;
1818

1919
let compNum = 0

maths/binary_convert.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @function BinaryConvert
2+
* @function binaryConvert
33
* @description Convert the decimal to binary.
44
* @param {number} num - The input integer
55
* @return {string} - Binary of num.
66
* @see [BinaryConvert](https://www.programiz.com/javascript/examples/decimal-binary)
7-
* @example BinaryConvert(12) = 1100
8-
* @example BinaryConvert(12 + 2) = 1110
7+
* @example binaryConvert(12) = 1100
8+
* @example binaryConvert(12 + 2) = 1110
99
*/
1010

11-
export const BinaryConvert = (num: number): string => {
11+
export const binaryConvert = (num: number): string => {
1212
let binary = ''
1313

1414
while (num !== 0) {

maths/binomial_coefficient.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Factorial } from "./factorial";
1+
import { factorial } from "./factorial";
22
/**
3-
* @function BinomialCoefficient
3+
* @function binomialCoefficient
44
* @description Calculate the binomial coefficient (n choose k) of two input numbers.
55
* @param {number} n - the total number of items
66
* @param {number} k - the number of items to be chosen
77
* @return {number} - Binomial coefficient (n choose k)
88
* @see https://en.wikipedia.org/wiki/Binomial_coefficient
9-
* @example BinomialCoefficient(5, 2) = 10
10-
* @example BinomialCoefficient(10, 3) = 120
11-
* @example BinomialCoefficient(6, 0) = 1
9+
* @example binomialCoefficient(5, 2) = 10
10+
* @example binomialCoefficient(10, 3) = 120
11+
* @example binomialCoefficient(6, 0) = 1
1212
*/
1313

14-
export const BinomialCoefficient = (n: number, k: number): number => {
14+
export const binomialCoefficient = (n: number, k: number): number => {
1515
// Check if k is larger than n or negative
1616
if (k > n || k < 0) {
1717
return 0;
1818
}
1919

2020
// Calculate the binomial coefficient using the implemented factorial
21-
const numerator = Factorial(n);
22-
const denominator = Factorial(k) * Factorial(n - k);
21+
const numerator = factorial(n);
22+
const denominator = factorial(k) * factorial(n - k);
2323
return numerator / denominator;
2424
};

maths/digit_sum.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @function DigitSum
2+
* @function digitSum
33
* @description Calculate the sum of all digits of a natural number (number base 10).
44
* @param {number} num - A natural number.
55
* @return {number} - Sum of all digits of given natural number.
66
* @see https://en.wikipedia.org/wiki/Digit_sum
7-
* @example DigitSum(12) = 3
8-
* @example DigitSum(9045) = 18
7+
* @example digitSum(12) = 3
8+
* @example digitSum(9045) = 18
99
*/
1010

11-
export const DigitSum = (num: number): number => {
11+
export const digitSum = (num: number): number => {
1212
if (num < 0 || !Number.isInteger(num)) {
1313
throw new Error("only natural numbers are supported");
1414
}

maths/factorial.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/**
2-
* @function Factorial
2+
* @function factorial
33
* @description Calculate the factorial of a natural number.
44
* @param {number} num - A natural number.
55
* @return {number} - The factorial.
6-
* @see https://en.wikipedia.org/wiki/Factorial
7-
* @example Factorial(0) = 1
8-
* @example Factorial(3) = 6
6+
* @see https://en.wikipedia.org/wiki/factorial
7+
* @example factorial(0) = 1
8+
* @example factorial(3) = 6
99
*/
10-
export const Factorial = (num: number): number => {
10+
export const factorial = (num: number): number => {
1111
if (num < 0 || !Number.isInteger(num)) {
1212
throw new Error("only natural numbers are supported");
1313
}
1414

15-
return num === 0 ? 1 : num * Factorial(num - 1);
15+
return num === 0 ? 1 : num * factorial(num - 1);
1616
};

maths/factors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @function FindFactors
2+
* @function findFactors
33
* @description Find all the factors of a natural number.
44
* @param {number} num - A natural number.
55
* @return {Set<number>} - A set of all the factors of given natural number.
66
* @see https://en.wikipedia.org/wiki/Divisor
7-
* @example FindFactors(1) = [1]
8-
* @example FindFactors(4) = [1,2,4]
9-
* @example FindFactors(16) = [1,3,5,15]
7+
* @example findFactors(1) = [1]
8+
* @example findFactors(4) = [1,2,4]
9+
* @example findFactors(16) = [1,3,5,15]
1010
*/
11-
export const FindFactors = (num: number): Set<number> => {
11+
export const findFactors = (num: number): Set<number> => {
1212
if (num <= 0 || !Number.isInteger(num)) {
1313
throw new Error("Only natural numbers are supported.");
1414
}

maths/find_min.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* @function FindMin
2+
* @function findMin
33
* @description Find the minimum in an array of numbers.
44
* @param {Number[]} nums - An array of numbers.
55
* @return {Number} - The minimum.
66
* @see https://infinitbility.com/how-to-find-minimum-value-in-array-in-typescript/
7-
* @example FindMin([1,2,3,4,5]) = 1
8-
* @example FindMin([87,6,13,999]) = 6
9-
* @example FindMin([0.8,0.2,0.3,0.5]) = 0.2
10-
* @example FindMin([1,0.1,-1]) = -1
7+
* @example findMin([1,2,3,4,5]) = 1
8+
* @example findMin([87,6,13,999]) = 6
9+
* @example findMin([0.8,0.2,0.3,0.5]) = 0.2
10+
* @example findMin([1,0.1,-1]) = -1
1111
*/
12-
export const FindMin = (nums: number[]): number => {
12+
export const findMin = (nums: number[]): number => {
1313
if (nums.length === 0) {
1414
throw new Error("array must have length of 1 or greater");
1515
}

maths/greatest_common_factor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function GreatestCommonFactor
2+
* @function greatestCommonFactor
33
* @description Determine the greatest common factor of a group of numbers.
44
* @param {Number[]} nums - An array of numbers.
55
* @return {Number} - The greatest common factor.

0 commit comments

Comments
 (0)