Skip to content

Commit c9b3d38

Browse files
authored
chore: fix naming convention for maths functions (#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

+5-5
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

+4-4
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

+4-4
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

+4-4
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

+8-8
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

+4-4
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

+6-6
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

+5-5
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

+6-6
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

+1-1
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.

maths/hamming_distance.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function HammingDistance
2+
* @function hammingDistance
33
* @description Returns the Hamming distance between two strings of equal length
44
* @summary The Hamming distance between two strings of equal length is the
55
* number of positions at which the corresponding symbols are different. In other words,
@@ -10,9 +10,9 @@
1010
* @param str2 One of the strings to compare to the other
1111
* @returns {number}
1212
* @see [Wikipedia](https://en.wikipedia.org/wiki/Hamming_distance)
13-
* @example HammingDistance('happy', 'homie')
13+
* @example hammingDistance('happy', 'homie')
1414
*/
15-
const HammingDistance = (str1: string, str2: string) => {
15+
const hammingDistance = (str1: string, str2: string) => {
1616
if (str1.length !== str2.length) throw new Error('Strings must of the same length.')
1717

1818
let dist = 0
@@ -22,4 +22,4 @@ const HammingDistance = (str1: string, str2: string) => {
2222
return dist
2323
}
2424

25-
export { HammingDistance }
25+
export { hammingDistance }

maths/is_divisible.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @function IsDivisible
2+
* @function isDivisible
33
* @description Checks is number is divisible by another number without remainder.
44
* @param {number} num1 - first number, a dividend.
55
* @param {number} num2 - second number, a divisor.
66
* @return {boolean} - true if first number can be divided by second number without a remainder.
7-
* @example IsDivisible(10, 2) = true
8-
* @example IsDivisible(11, 3) = false
7+
* @example isDivisible(10, 2) = true
8+
* @example isDivisible(11, 3) = false
99
*/
1010

11-
export const IsDivisible = (num1: number, num2: number): boolean => {
11+
export const isDivisible = (num1: number, num2: number): boolean => {
1212
if (num2 === 0) {
1313
throw new Error('Cannot divide by 0');
1414
}

maths/is_even.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* @function IsEven
2+
* @function isEven
33
* @description Determine whether a number is even.
44
* @param {Number} num - A number.
55
* @return {Boolean} - Whether the given number is even.
66
* @see https://en.wikipedia.org/wiki/Parity_(mathematics)
7-
* @example IsEven(1) = false
8-
* @example IsEven(2) = true
7+
* @example isEven(1) = false
8+
* @example isEven(2) = true
99
*/
10-
export const IsEven = (num: number): boolean => {
10+
export const isEven = (num: number): boolean => {
1111
if (!Number.isInteger(num)) {
1212
throw new Error("only integers can be even or odd");
1313
}

maths/is_leap_year.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* @function IsLeapYear
2+
* @function isLeapYear
33
* @description Checks if a year is a leap year (Gregorian calendar).
44
* A year is a leap year if it is divisible by 4 but not by 400 or if it is divisible by 400.
55
* @param {number} year - A year, natural number > 0.
66
* @return {boolean} - True if given year is a leap year.
77
* @see https://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar
8-
* @example IsLeapYear(2000) = true
9-
* @example IsLeapYear(2001) = false
8+
* @example isLeapYear(2000) = true
9+
* @example isLeapYear(2001) = false
1010
*/
1111

12-
export const IsLeapYear = (year: number): boolean => {
12+
export const isLeapYear = (year: number): boolean => {
1313
if (year <= 0 || !Number.isInteger(year)) {
1414
throw new Error("year must be a natural number > 0");
1515
}

maths/is_odd.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* @function IsOdd
2+
* @function isOdd
33
* @description Determine whether a number is odd.
44
* @param {Number} num - A number.
55
* @return {Boolean} - Whether the given number is odd.
66
* @see https://en.wikipedia.org/wiki/Parity_(mathematics)
7-
* @example IsOdd(1) = true
8-
* @example IsOdd(2) = false
7+
* @example isOdd(1) = true
8+
* @example isOdd(2) = false
99
*/
10-
export const IsOdd = (num: number): boolean => {
10+
export const isOdd = (num: number): boolean => {
1111
if (!Number.isInteger(num)) {
1212
throw new Error("only integers can be even or odd");
1313
}

maths/is_palindrome.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param number The input number.
77
* @return {boolean} Wether the number is a Palindrome or not.
88
*/
9-
export const IsPalindrome = (number: number): boolean => {
9+
export const isPalindrome = (number: number): boolean => {
1010
if (number < 0 || (number % 10 === 0 && number !== 0)) {
1111
return false;
1212
}

maths/lowest_common_multiple.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function LowestCommonMultiple
2+
* @function lowestCommonMultiple
33
* @description Determine the lowest common multiple of a group of numbers.
44
* @param {Number[]} nums - An array of numbers.
55
* @return {Number} - The lowest common multiple.

maths/number_of_digits.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* @function NumberOfDigits
2+
* @function numberOfDigits
33
* @description Calculate the number of digits of a natural number.
44
* @param {number} num - A natural number.
55
* @return {number} - Number of digits of given natural number.
66
* @see https://math.stackexchange.com/a/231745/518862
7-
* @example NumberOfDigits(18) = 2
8-
* @example NumberOfDigits(294568) = 6
9-
* @example NumberOfDigits(128798319794) = 12
7+
* @example numberOfDigits(18) = 2
8+
* @example numberOfDigits(294568) = 6
9+
* @example numberOfDigits(128798319794) = 12
1010
*/
1111

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

maths/perfect_square.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* @param {num} number
77
*/
88

9-
export const PerfectSquare = (num: number) => {
9+
export const perfectSquare = (num: number) => {
1010
return Number.isInteger(Math.sqrt(num));
1111
};

maths/pronic_number.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @function PronicNumber
2+
* @function pronicNumber
33
* @description Checks whether a given number is a pronic number or not
44
* @summary Pronic numbers, or oblong numbers as they are often referred to as,
55
* are numbers which are the product of two consecutive integers. That is,
@@ -9,16 +9,16 @@
99
* @param num The number to check for being pronic
1010
* @returns {boolean} Whether the number is pronic or not
1111
* @see [Wikipedia](https://en.wikipedia.org/wiki/Pronic_number)
12-
* @example PronicNumber(20) = true
13-
* @example PronicNumber(30) = true
14-
* @example PronicNumber(49) = false
12+
* @example pronicNumber(20) = true
13+
* @example pronicNumber(30) = true
14+
* @example pronicNumber(49) = false
1515
*/
16-
const PronicNumber = (n: number) => {
16+
const pronicNumber = (n: number) => {
1717
if (isNaN(n)) throw new Error('The input needs to be a number')
1818
if (!Number.isInteger(n) || n < 0) throw new Error('The input needs to be a non-negative integer')
1919
if (n === 0) return true
2020

2121
return !Number.isInteger(Math.sqrt(n)) && Math.floor(Math.sqrt(n)) * Math.ceil(Math.sqrt(n)) === n
2222
}
2323

24-
export { PronicNumber }
24+
export { pronicNumber }

maths/sieve_of_eratosthenes.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* @function SieveOfEratosthenes
2+
* @function sieveOfEratosthenes
33
* @description Find the prime numbers between 2 and n
44
* @param {number} n - numbers set the limit that the algorithm needs to look to find the primes
55
* @return {number[]} - List of prime numbers
66
* @see https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\
7-
* @example SieveOfErastosthenes(5) = [2,3,5]
8-
* @example SieveOfErastosthenes(10) = [2,3,5,7]
7+
* @example sieveOfEratosthenes(5) = [2,3,5]
8+
* @example sieveOfEratosthenes(10) = [2,3,5,7]
99
*/
1010

11-
export function SieveOfEratosthenes(n: number): number[] {
11+
export function sieveOfEratosthenes(n: number): number[] {
1212
if (n < 0 || !Number.isInteger(n)) {
1313
throw new Error("Only natural numbers are supported");
1414
}

0 commit comments

Comments
 (0)