Skip to content

Commit 7ae0aad

Browse files
committed
fixing JSDOCS for some files in Math folder that missing it
1 parent fb5530f commit 7ae0aad

15 files changed

+87
-16
lines changed

Diff for: Maths/ArmstrongNumber.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* An Armstrong number is equal to the sum of its own digits each raised to the power of the number of digits.
66
* For example, 370 is an Armstrong number because 3*3*3 + 7*7*7 + 0*0*0 = 370.
77
* An Armstrong number is often called Narcissistic number.
8-
*
8+
* @param {number} num - The number to check if it is an Armstrong number.
9+
* @returns {boolean} - True if the number is an Armstrong number, false otherwise.
910
*/
1011

1112
const armstrongNumber = (num) => {

Diff for: Maths/AverageMedian.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
* if the length of the array is even number, the median value will be the average of the two middle numbers
88
* else if the length of the array is odd number, the median value will be the middle number in the array
99
*/
10-
10+
/**
11+
* Function to find the median value of an array of numbers.
12+
* @param {number[]}
13+
* @returns {number} - The median value of the array.
14+
*/
1115
const averageMedian = (sourceArrayOfNumbers) => {
1216
const numbers = [...sourceArrayOfNumbers].sort(sortNumbers)
1317
const numLength = numbers.length
@@ -16,7 +20,12 @@ const averageMedian = (sourceArrayOfNumbers) => {
1620
? (numbers[numLength / 2 - 1] + numbers[numLength / 2]) / 2
1721
: numbers[Math.floor(numLength / 2)]
1822
}
19-
23+
/**
24+
* Comparator function to sort numbers in ascending order.
25+
* @param {number} num1
26+
* @param {number} num2
27+
* @returns {number}
28+
*/
2029
const sortNumbers = (num1, num2) => num1 - num2
2130

2231
export { averageMedian }

Diff for: Maths/CheckKishnamurthyNumber.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
*/
77

88
// factorial utility method.
9+
/**
10+
* @param {Number} n
11+
* @returns {Number} the factiorial of n
12+
*/
913
const factorial = (n) => {
1014
let fact = 1
1115
while (n !== 0) {

Diff for: Maths/Coordinate.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
Example: coorDistance(2,2,14,11) will return 15
55
Wikipedia reference: https://en.wikipedia.org/wiki/Geographical_distance#Flat-surface_formulae
66
*/
7+
/**
8+
* @param {number} longitude1 - The longitude of the first point.
9+
* @param {number} latitude1 - The latitude of the first point.
10+
* @param {number} longitude2 - The longitude of the second point.
11+
* @param {number} latitude2 - The latitude of the second point.
12+
* @returns {number} - The Euclidean distance between the two points.
13+
*/
714
const euclideanDistance = (longitude1, latitude1, longitude2, latitude2) => {
815
const width = longitude2 - longitude1
916
const height = latitude2 - latitude1
1017
return Math.sqrt(width * width + height * height)
1118
}
12-
19+
/*
20+
* @param {number} longitude1 - The longitude of the first point.
21+
* @param {number} latitude1 - The latitude of the first point.
22+
* @param {number} longitude2 - The longitude of the second point.
23+
* @param {number} latitude2 - The latitude of the second point.
24+
* @returns {number} - The Manhattan distance between the two points.
25+
*/
1326
const manhattanDistance = (longitude1, latitude1, longitude2, latitude2) => {
1427
const width = Math.abs(longitude2 - longitude1)
1528
const height = Math.abs(latitude2 - latitude1)

Diff for: Maths/EulersTotient.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
Complexity:
88
O(sqrt(n))
99
*/
10-
10+
/**
11+
*
12+
* @param {Number} n
13+
* @returns {Number} count of numbers b/w 1 and n that are coprime to n
14+
*/
1115
export const EulersTotient = (n) => {
12-
// input: n: int
13-
// output: phi(n): count of numbers b/w 1 and n that are coprime to n
1416
let res = n
1517
for (let i = 2; i * i <= n; i++) {
1618
if (n % i === 0) {

Diff for: Maths/EulersTotientFunction.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
so EulersTotientFunction(n) (or phi(n)) is the count of numbers in {1,2,3,....,n} that are relatively
88
prime to n, i.e., the numbers whose GCD (Greatest Common Divisor) with n is 1.
99
*/
10-
10+
/**
11+
*
12+
* @param {Number} x
13+
* @param {Number} y
14+
* @returns {Number} compute greatest common divisor for x and y
15+
*/
1116
const gcdOfTwoNumbers = (x, y) => {
1217
// x is smaller than y
1318
// let gcd of x and y is gcdXY

Diff for: Maths/Factors.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* https://www.mathsisfun.com/definitions/factor.html
77
*
88
*/
9-
9+
/**
10+
* @param {Number} [number=0]
11+
*/
1012
const factorsOfANumber = (number = 0) => {
1113
return Array.from(Array(number + 1).keys()).filter(
1214
(num) => number % num === 0

Diff for: Maths/FindHcf.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
More about HCF:
44
https://en.wikipedia.org/wiki/Greatest_common_divisor
55
*/
6-
6+
/**
7+
*
8+
* @param {Number} x
9+
* @param {Number} y
10+
* @returns {(string|number)}
11+
*/
712
const findHCF = (x, y) => {
813
// If the input numbers are less than 1 return an error message.
914
if (x < 1 || y < 1) {

Diff for: Maths/FindLcm.js

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
import { findHCF } from './FindHcf'
1515

1616
// Find the LCM of two numbers.
17+
/**
18+
*
19+
* @param {Number} num1
20+
* @param {Number} num2
21+
* @returns
22+
*/
1723
const findLcm = (num1, num2) => {
1824
// If the input numbers are less than 1 return an error message.
1925
if (num1 < 1 || num2 < 1) {

Diff for: Maths/FriendlyNumbers.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
Source: https://en.wikipedia.org/wiki/Friendly_number
55
See also: https://mathworld.wolfram.com/FriendlyNumber.html#:~:text=The%20numbers%20known%20to%20be,numbers%20have%20a%20positive%20density.
66
*/
7-
7+
/**
8+
* @param {Number} firstNumber,
9+
* @param {Number} secondNumber
10+
*/
811
export const FriendlyNumbers = (firstNumber, secondNumber) => {
912
// input: two integers
1013
// output: true if the two integers are friendly numbers, false if they are not friendly numbers
@@ -22,11 +25,17 @@ export const FriendlyNumbers = (firstNumber, secondNumber) => {
2225

2326
return abundancyIndex(firstNumber) === abundancyIndex(secondNumber)
2427
}
25-
28+
/**
29+
* @param {Number} number
30+
*/
2631
function abundancyIndex(number) {
2732
return sumDivisors(number) / number
2833
}
29-
34+
/**
35+
*
36+
* @param {Number} number
37+
* @returns
38+
*/
3039
function sumDivisors(number) {
3140
let runningSumDivisors = number
3241
for (let i = 0; i < number / 2; i++) {

Diff for: Maths/IsDivisible.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Checks if a number is divisible by another number.
2-
2+
/**
3+
*
4+
* @param {Number} num1
5+
* @param {Number} num2
6+
* @throws {TypeError}
7+
* @returns {boolean}
8+
*/
39
export const isDivisible = (num1, num2) => {
410
if (!Number.isFinite(num1) || !Number.isFinite(num2)) {
511
throw new TypeError('Expected a valid real number')

Diff for: Maths/LinearSieve.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
*
3+
* @param {Number} n
4+
* @returns {Number[]} array of prime numbers untill number n
5+
*/
16
const LinearSieve = (n) => {
27
/*
38
* Calculates prime numbers till a number n

Diff for: Maths/MatrixExponentiationRecursive.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
where: d is the dimension of the square matrix
88
n is the power the matrix is raised to
99
*/
10-
10+
/**
11+
*
12+
* @param {Number} n
13+
* @returns {Number[][]}
14+
*/
1115
const Identity = (n) => {
1216
// Input: n: int
1317
// Output: res: Identity matrix of size n x n

Diff for: Maths/ModularBinaryExponentiationRecursive.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Explanation:
66
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
77
*/
8-
98
const modularBinaryExponentiation = (a, n, m) => {
109
// input: a: int, n: int, m: int
1110
// returns: (a^n) % m: int

Diff for: Maths/PerfectCube.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* License: GPL-3.0 or later
44
*
55
* This uses `round` instead of `floor` or `trunc`, to guard against potential `cbrt` accuracy errors
6+
* @param {Number} num
67
*/
78

89
const perfectCube = (num) =>

0 commit comments

Comments
 (0)