Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding fix #1342 fixing docs for FenWickTree and DepthFirstSearch #1647

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1650272
adding fix #1342 fixing docs for FenWickTree and DepthFirstSearch
mohmmadAyesh Mar 27, 2024
96985a6
fix the coding style to pass code-style check
mohmmadAyesh Mar 27, 2024
5aa8bfa
adding JSDOCS for BreadthFirstTreeTraversal.js and formatting the new…
mohmmadAyesh Mar 27, 2024
575eead
adding JSDOCS for the following files BoyerMoore checkRearrangedPalin…
mohmmadAyesh Mar 27, 2024
18edde7
fixing JSDOCS for Sorts Folder the folder that been modified are Alph…
mohmmadAyesh Mar 27, 2024
1ec1979
adding js docs to files that missing it in search folder like binaryS…
mohmmadAyesh Mar 27, 2024
ae93e49
fixing formatting to avoid code/style workflow fail
mohmmadAyesh Mar 27, 2024
7560357
fixing or applying suggested changes
mohmmadAyesh Mar 27, 2024
c70f197
Merge remote-tracking branch 'origin/fixing-JS-docs-for-Sorts-Folder'…
mohmmadAyesh Mar 27, 2024
8f10dee
Merge remote-tracking branch 'origin/fixing-JS-docs-for-Search-Folder…
mohmmadAyesh Mar 27, 2024
de118c6
Merge remote-tracking branch 'origin/fixing-string-folder-JSDOCS' int…
mohmmadAyesh Mar 27, 2024
d64f4c9
fixing formatting to pass code/style automatic test
mohmmadAyesh Mar 27, 2024
f9a154b
adding more commits on fix-js-docs
mohmmadAyesh Mar 28, 2024
1d37ed9
fixing styling and formatting
mohmmadAyesh Mar 28, 2024
d9cc779
try to resolve not belonging commit
mohmmadAyesh Mar 27, 2024
ad98cee
Resolve conflict in CheckPalindrome.js during cherry-pick
mohmmadAyesh Mar 27, 2024
8d5cc4b
Resolve merge conflict in checkPalindrome function
mohmmadAyesh Mar 27, 2024
fb5530f
fixing JSDOCS for some files in Recursive folder
mohmmadAyesh Mar 28, 2024
7ae0aad
fixing JSDOCS for some files in Math folder that missing it
mohmmadAyesh Mar 28, 2024
2f74313
fixing styling and formating of files in Maths folder to pass automat…
mohmmadAyesh Mar 28, 2024
3d06ddf
fixing formating of MobiusFunction.js
mohmmadAyesh Mar 29, 2024
780fb91
trying to fix spelling in LucasSeries.js
mohmmadAyesh Mar 29, 2024
714cd66
fixing spelling at LinearSieve.js
mohmmadAyesh Mar 29, 2024
53035ec
remove unnecessary changes
mohmmadAyesh Mar 29, 2024
42b95ed
modifying only jsdocs of BinaryToDecimal RGBToHex in Conversions folder
mohmmadAyesh Mar 29, 2024
d82e849
modifiying JSDOCS for uniquepath and zerooneknapsack files in dynamic…
mohmmadAyesh Mar 29, 2024
8aab6f9
modifying jsdocs at unique paths at dynamic folder
mohmmadAyesh Mar 29, 2024
7651b8b
modifying JSDOCS at BinaryLifting file at Graphs Folder
mohmmadAyesh Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Conversions/BinaryToDecimal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Converts a binary string to a decimal number.
*
* @param {string} binaryString - The binary string to be converted to decimal.
* @returns {number} The decimal representation of the binary string.
*/
export default function binaryToDecimal(binaryString) {
let decimalNumber = 0
const binaryDigits = binaryString.split('').reverse() // Splits the binary number into reversed single digits
Expand Down
9 changes: 9 additions & 0 deletions Conversions/RGBToHex.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Converts RGB color values to a hexadecimal color code.
*
* @param {number} r - The red color value (0-255).
* @param {number} g - The green color value (0-255).
* @param {number} b - The blue color value (0-255).
* @returns {string} The hexadecimal color code representing the RGB values.
* @throws {TypeError} If any of the arguments is not a number.
*/
function RGBToHex(r, g, b) {
if (typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number') {
throw new TypeError('argument is not a Number')
Expand Down
2 changes: 1 addition & 1 deletion Dynamic-Programming/UniquePaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* More info: https://leetcode.com/problems/unique-paths/
*/

/*
/**
* @param {number} m
* @param {number} n
* @return {number}
Expand Down
5 changes: 5 additions & 0 deletions Dynamic-Programming/ZeroOneKnapsack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* https://en.wikipedia.org/wiki/Knapsack_problem
*
* Time and Space Complexity: O(n*cap)
* @param {Array<[number, number]>} arr - An array of tuples representing the weights and values of items.
* @param {number} n - The number of items available.
* @param {number} cap - The capacity of the thief's bag.
* @param {Array<Array<number>>} cache - A 2D array to cache computed values for dynamic programming.
* @returns {number} The maximum value that can be stolen.
*/
const zeroOneKnapsack = (arr, n, cap, cache) => {
// Base Case: No capacity or no items
Expand Down
9 changes: 8 additions & 1 deletion Graphs/BinaryLifting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Author: Adrito Mukherjee
* @class BinaryLifting
* Binary Lifting implementation in Javascript
* Binary Lifting is a technique that is used to find the kth ancestor of a node in a rooted tree with N nodes
* @classdesc Binary Lifting is a technique that is used to find the kth ancestor of a node in a rooted tree with N nodes
* The technique requires preprocessing the tree in O(N log N) using dynamic programming
* The technique can answer Q queries about kth ancestor of any node in O(Q log N)
* It is faster than the naive algorithm that answers Q queries with complexity O(Q K)
Expand All @@ -10,6 +11,12 @@
*/

export class BinaryLifting {
/**
* Creates an instance of BinaryLifting.
* @template T
* @param {T} root
* @param {Array<[T, T]>} tree - The edges of the tree represented as an array of pairs.
*/
constructor(root, tree) {
this.root = root
this.connections = new Map()
Expand Down
3 changes: 2 additions & 1 deletion Maths/ArmstrongNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* An Armstrong number is equal to the sum of its own digits each raised to the power of the number of digits.
* For example, 370 is an Armstrong number because 3*3*3 + 7*7*7 + 0*0*0 = 370.
* An Armstrong number is often called Narcissistic number.
*
* @param {number} num - The number to check if it is an Armstrong number.
* @returns {boolean} - True if the number is an Armstrong number, false otherwise.
*/

const armstrongNumber = (num) => {
Expand Down
13 changes: 11 additions & 2 deletions Maths/AverageMedian.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* if the length of the array is even number, the median value will be the average of the two middle numbers
* else if the length of the array is odd number, the median value will be the middle number in the array
*/

/**
* Function to find the median value of an array of numbers.
* @param {number[]}
* @returns {number} - The median value of the array.
*/
const averageMedian = (sourceArrayOfNumbers) => {
const numbers = [...sourceArrayOfNumbers].sort(sortNumbers)
const numLength = numbers.length
Expand All @@ -16,7 +20,12 @@ const averageMedian = (sourceArrayOfNumbers) => {
? (numbers[numLength / 2 - 1] + numbers[numLength / 2]) / 2
: numbers[Math.floor(numLength / 2)]
}

/**
* Comparator function to sort numbers in ascending order.
* @param {number} num1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three lines starting here are not useful.

* @param {number} num2
* @returns {number}
*/
const sortNumbers = (num1, num2) => num1 - num2

export { averageMedian }
4 changes: 4 additions & 0 deletions Maths/CheckKishnamurthyNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

// factorial utility method.
/**
* @param {Number} n
* @returns {Number} the factiorial of n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: factiorial (I would also say this is self-explanatory, and since it's just a helper, doesn't need a comment; ideally this file should import the factorial implementation).

*/
const factorial = (n) => {
let fact = 1
while (n !== 0) {
Expand Down
15 changes: 14 additions & 1 deletion Maths/Coordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
Example: coorDistance(2,2,14,11) will return 15
Wikipedia reference: https://en.wikipedia.org/wiki/Geographical_distance#Flat-surface_formulae
*/
/**
* @param {number} longitude1 - The longitude of the first point.
* @param {number} latitude1 - The latitude of the first point.
* @param {number} longitude2 - The longitude of the second point.
* @param {number} latitude2 - The latitude of the second point.
* @returns {number} - The Euclidean distance between the two points.
*/
const euclideanDistance = (longitude1, latitude1, longitude2, latitude2) => {
const width = longitude2 - longitude1
const height = latitude2 - latitude1
return Math.sqrt(width * width + height * height)
}

/*
* @param {number} longitude1 - The longitude of the first point.
* @param {number} latitude1 - The latitude of the first point.
* @param {number} longitude2 - The longitude of the second point.
* @param {number} latitude2 - The latitude of the second point.
* @returns {number} - The Manhattan distance between the two points.
*/
const manhattanDistance = (longitude1, latitude1, longitude2, latitude2) => {
const width = Math.abs(longitude2 - longitude1)
const height = Math.abs(latitude2 - latitude1)
Expand Down
8 changes: 5 additions & 3 deletions Maths/EulersTotient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
Complexity:
O(sqrt(n))
*/

/**
*
* @param {Number} n
* @returns {Number} count of numbers b/w 1 and n that are coprime to n
Copy link
Collaborator

@appgurueu appgurueu Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"b/w" is confusing. Please write "between" out. This should also be consolidated with the definition given above.

*/
export const EulersTotient = (n) => {
// input: n: int
// output: phi(n): count of numbers b/w 1 and n that are coprime to n
let res = n
for (let i = 2; i * i <= n; i++) {
if (n % i === 0) {
Expand Down
7 changes: 6 additions & 1 deletion Maths/EulersTotientFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
so EulersTotientFunction(n) (or phi(n)) is the count of numbers in {1,2,3,....,n} that are relatively
prime to n, i.e., the numbers whose GCD (Greatest Common Divisor) with n is 1.
*/

/**
*
* @param {Number} x
* @param {Number} y
* @returns {Number} compute greatest common divisor for x and y
*/
const gcdOfTwoNumbers = (x, y) => {
// x is smaller than y
// let gcd of x and y is gcdXY
Expand Down
4 changes: 3 additions & 1 deletion Maths/Factors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* https://www.mathsisfun.com/definitions/factor.html
*
*/

/**
* @param {Number} [number=0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not useful.

*/
const factorsOfANumber = (number = 0) => {
return Array.from(Array(number + 1).keys()).filter(
(num) => number % num === 0
Expand Down
7 changes: 6 additions & 1 deletion Maths/FindHcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
More about HCF:
https://en.wikipedia.org/wiki/Greatest_common_divisor
*/

/**
*
* @param {Number} x
* @param {Number} y
* @returns {(string|number)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be explained; ideallly the errors should be thrown instead of returned.

*/
const findHCF = (x, y) => {
// If the input numbers are less than 1 return an error message.
if (x < 1 || y < 1) {
Expand Down
6 changes: 6 additions & 0 deletions Maths/FindLcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import { findHCF } from './FindHcf'

// Find the LCM of two numbers.
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unhelpful comment

*
* @param {Number} num1
* @param {Number} num2
* @returns
*/
const findLcm = (num1, num2) => {
// If the input numbers are less than 1 return an error message.
if (num1 < 1 || num2 < 1) {
Expand Down
15 changes: 12 additions & 3 deletions Maths/FriendlyNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
Source: https://en.wikipedia.org/wiki/Friendly_number
See also: https://mathworld.wolfram.com/FriendlyNumber.html#:~:text=The%20numbers%20known%20to%20be,numbers%20have%20a%20positive%20density.
*/

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this comment is unhelpful

* @param {Number} firstNumber,
* @param {Number} secondNumber
*/
export const FriendlyNumbers = (firstNumber, secondNumber) => {
// input: two integers
// output: true if the two integers are friendly numbers, false if they are not friendly numbers
Expand All @@ -22,11 +25,17 @@ export const FriendlyNumbers = (firstNumber, secondNumber) => {

return abundancyIndex(firstNumber) === abundancyIndex(secondNumber)
}

/**
* @param {Number} number
*/
function abundancyIndex(number) {
return sumDivisors(number) / number
}

/**
*
* @param {Number} number
* @returns
*/
function sumDivisors(number) {
let runningSumDivisors = number
for (let i = 0; i < number / 2; i++) {
Expand Down
8 changes: 7 additions & 1 deletion Maths/IsDivisible.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Checks if a number is divisible by another number.

/**
*
* @param {Number} num1
* @param {Number} num2
* @throws {TypeError}
* @returns {boolean}
*/
export const isDivisible = (num1, num2) => {
if (!Number.isFinite(num1) || !Number.isFinite(num2)) {
throw new TypeError('Expected a valid real number')
Expand Down
5 changes: 5 additions & 0 deletions Maths/LinearSieve.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
*
* @param {Number} n
* @returns {Number[]} array of prime numbers until number n
*/
const LinearSieve = (n) => {
/*
* Calculates prime numbers till a number n
Expand Down
6 changes: 5 additions & 1 deletion Maths/MatrixExponentiationRecursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
where: d is the dimension of the square matrix
n is the power the matrix is raised to
*/

/**
*
* @param {Number} n
* @returns {Number[][]}
*/
const Identity = (n) => {
// Input: n: int
// Output: res: Identity matrix of size n x n
Expand Down
1 change: 0 additions & 1 deletion Maths/ModularBinaryExponentiationRecursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Explanation:
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
*/

const modularBinaryExponentiation = (a, n, m) => {
// input: a: int, n: int, m: int
// returns: (a^n) % m: int
Expand Down
1 change: 1 addition & 0 deletions Maths/PerfectCube.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* License: GPL-3.0 or later
*
* This uses `round` instead of `floor` or `trunc`, to guard against potential `cbrt` accuracy errors
* @param {Number} num
*/

const perfectCube = (num) =>
Expand Down
11 changes: 10 additions & 1 deletion Recursive/KochSnowflake.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
* https://natureofcode.com/book/chapter-8-fractals/ #84-the-koch-curve-and-the-arraylist-technique).
*/

/** Class to handle the vector calculations. */
/** Class to handle the vector calculations.
* @class Vector2
*/
export class Vector2 {
/**
* Creates a new Vector2 instance.
* @constructor
* @param {number} x - The x component of the vector.
* @param {number} y - The y component of the vector.
*/

constructor(x, y) {
this.x = x
this.y = y
Expand Down
2 changes: 1 addition & 1 deletion Recursive/LetterCombination.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* More info: https://leetcode.com/problems/letter-combinations-of-a-phone-number/
*/

/*
/**
* @param {string} digits
* @returns {string[]} all the possible combinations
*/
Expand Down
11 changes: 11 additions & 0 deletions Recursive/PalindromePartitioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import { palindrome } from './Palindrome'
* A palindrome partitioning partitions a string into palindromic substrings.
* @see https://www.cs.columbia.edu/~sedwards/classes/2021/4995-fall/proposals/Palindrome.pdf
*/
/**
* Returns all possible palindrome partitionings of a given string.
* @param {string} s
* @returns {string[][]} - Array of arrays containing all possible palindrome partitionings.
*/
const partitionPalindrome = (s) => {
const result = []
backtrack(s, [], result)
return result
}

/**
* Backtracking function to find palindrome partitionings.
* @param {string} s - The remaining part of the string to be checked for partitioning.
* @param {string[]} path - Current partitioning path.
* @param {string[][]} result - Array to store all valid palindrome partitionings.
*/
const backtrack = (s, path, result) => {
if (s.length === 0) {
result.push([...path])
Expand Down
9 changes: 8 additions & 1 deletion Recursive/SubsequenceRecursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
* https://en.wikipedia.org/wiki/Subsequence
* https://en.wikipedia.org/wiki/Lexicographic_order
*/

/**
* Find all distinct, non-empty subsequences of a given string in lexicographical order using a recursive approach.
* @param {string} str
* @param {string} seq
* @param {number} low
* @param {string[]} [output=[]]
* @returns {string[]}
*/
export const subsequence = (str, seq, low, output = []) => {
if (low <= str.length && str.length !== 0) {
output.push(seq)
Expand Down
10 changes: 9 additions & 1 deletion Recursive/TowerOfHanoi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// wiki - https://en.wikipedia.org/wiki/Tower_of_Hanoi
// Recursive Javascript function to solve tower of hanoi

/**
* Solves the Tower of Hanoi problem recursively.
* @param {number} n - The number of disks to move.
* @param {string} from - The rod from which to move the disks.
* @param {string} to - The rod to which to move the disks.
* @param {string} aux - The auxiliary rod for moving disks.
* @param {string[]} [output=[]] - Optional array to store the sequence of moves.
* @returns {string[]} The sequence of moves to solve the Tower of Hanoi problem.
*/
export function TowerOfHanoi(n, from, to, aux, output = []) {
if (n === 1) {
output.push(`Move disk 1 from rod ${from} to rod ${to}`)
Expand Down
Loading
Loading