Algebra

Following are the Algebraic functions in Chelsea.js
All the functions are briefly explained with examples and easy-to-understand language.

Power

Calculates a number raised to a power. In simpler words, x to the power of y is equal to x multiplied by itself y times.
For example, 2 to the power of 3 is equal to 2 multiplied by itself 3 times i.e. 8.

                
    pow(x, y);

    pow(2, 3);     // returns 8
    pow(3, 2);     // returns 9   
            

Square Root

The square root of a number is the number that when multiplied by itself, equals the original number.
For example, the square root of 16 is 4.

                
    sqrt(x);

    sqrt(16);     // returns 4   
            

Cube Root

The cube root of a number is the number that when multiplied by itself three times, equals the original number.
For example, the cube root of 27 is 3.

                
    cbrt(x);

    cbrt(27);    // returns 3   
            

Exponential

The exponential function returns the value of e raised to the power of the value of x.
For example, the exponential of 3 is equal to e to the power of 3.

                
    exp(x);

    exp(3);     // returns 20.085536923187668   
            

Logarithm

The logarithm function returns the natural logarithm (base e) of a number.
For example, the logarithm of 3 is equal to the natural logarithm of 3.

                
    log(x);

    log(3);      // returns 1.0986122886681098   
    log(10);     // returns 2.302585092994046   
    log(E);      // returns 1   
    

Logarithm Base 10

The logarithm base 10 function returns the common logarithm (base 10) of a number.
For example, the logarithm base 10 of 3 is equal to the common logarithm of 3.

                
    log10(x);

    log10(3);     // returns 0.47712125471966244   
    log10(10);    // returns 1   
    log10(E);     // returns 0.4342944819032518  
    

Absolute

The absolute function returns the absolute value(magnitude) of a number.
The absolute value of a number is always positive.

                    
    abs(x);

    abs(-5);      // returns 5
    abs(5);       // returns 5   
                

Floor

The floor function returns the largest integer less than or equal to a number.
For example, the floor of 3.14 is equal to 3.

                    
    floor(x);

    floor(3.14);  // returns 3
    floor(3.9);   // returns 3   
                

Ceil

The ceil function returns the smallest integer greater than or equal to a number.
For example, the ceil of 3.14 is equal to 4.

                    
    ceil(x);

    ceil(3.14);   // returns 4
    ceil(3.9);    // returns 4   
                

Round

The round function returns the value of a number rounded to the nearest integer.
For example, the round of 3.14 is equal to 3.

                    
    round(x);

    round(3.14);  // returns 3
    round(3.6);   // returns 4
    round(3.5);   // returns 4
    

Maximum

The maximum function returns the largest of two or more numbers.
For example, the maximum of 3 and 4 is equal to 4.

        
    max([array]);

    max([3, 4]);    // returns 4
    max([3, 4, 1, 2, 3]); // returns 4   
    

Minimum

The minimum function returns the smallest of two or more numbers.
For example, the minimum of 3 and 4 is equal to 3.

        
    min([array]);

    min([3, 4]);    // returns 3
    min([3, 4, 1, 2, 4, 5, 7, 3]); // returns 1 


Factorial

The factorial function returns the factorial of a number. In simpler words factorial of a number is equal to the product of all the numbers from 1 to the number itself.
For example, the factorial of 3 is equal to 3 multiplied by 2 multiplied by 1.

$$ \text{factorial}(x) = x! = (x) \times (x-1) \times (x-2) \times (x-3) ... \times 1 $$
    
    factorial(x);

    factorial(3);     // returns 6
    factorial(5);     // returns 120   
    factorial(20);    // returns 2432902008176640000

\( \newcommand{\Perm}[2]{{}^{#1}\!P_{#2}} \newcommand{\Comb}[2]{{}^{#1}C_{#2}} \)

Combinations

The combinations function returns the number of combinations of a set of objects.
For example, the combinations of 2 objects in a set of 3 objects is equal to 3.
In simpler words, lets say we have three balls : [red, green, blue].
Then all possible combinations of two objects are : [red, green], [red, blue], [green, blue].
i.e. $$ \Comb{3}{2} = 3$$ $$ \text{combinations}(n, k) = \frac{n!}{k!(n-k)!}= \Comb{n}{k} $$

    
    combinations(n, k);

    combinations(3, 2);     // returns 3
    combinations(4, 2);     // returns 6
    combinations(5, 2);     // returns 10
    combinations(6, 2);     // returns 15
    combinations(7, 2);     // returns 21
    combinations(8, 2);     // returns 28
    combinations(9, 2);     // returns 36
    combinations(10, 2);    // returns 45
    

Permutations

The permutations function returns the number of permutations of a set of objects.
For example, the permutations of 2 objects in a set of 3 objects is equal to 6.
In simpler words, lets say we have three balls : [red, green, blue].
Then all possible permutations of two objects are :
[red, green], [red, blue], [ green, blue],[ green, red], [blue, red], [blue, green].
i.e. $$ \Perm{3}{2} = 6$$ $$ \text{permutations}(n, k) = \frac{n!}{(n-k)!}= \Perm{n}{k} $$

    
    permutations(n, k);

    permutations(3, 2);     // returns 6
    permutations(4, 2);     // returns 12
    permutations(5, 2);     // returns 20
    permutations(6, 2);     // returns 30
    permutations(7, 2);     // returns 42
    permutations(8, 2);     // returns 56
    permutations(9, 2);     // returns 72
    permutations(10, 2);    // returns 90
    

Make Combinations

Returns an array of all possible combinations of two objects in the given array.

For example, lets say we have three balls : [red, green, blue].
Then all possible combinations of two objects are : [red, green], [red, blue], [green, blue].
This function returns the array:

[[red, green],
[red, blue],
[green, blue]]

    
    makeCombinations(arr);

    makeCombinations([1, 2, 3]);         // returns [[1, 2], [1, 3], [2, 3]]
    makeCombinations([🔴,🔵,🟢,🟣]);   // returns [[🔴,🔵], [🔴,🟢], [🔴,🟣], [🔵,🟢], [🔵,🟣], [🟢,🟣]]