Math API
odd()
Checks if an integer is odd.
- Type
- Details
Takes an integer as an argument; returns true if the integer is odd, otherwise returns false.
- Example
odd(114514); // falseodd(114514); // falseeven()
Checks if an integer is even.
- Type
- Details
Takes an integer as an argument; returns true if the integer is even, otherwise returns false.
- Example
even(114514); // trueeven(114514); // trueadd()
Calculates the sum of two numbers.
- Type
- Details
Takes two numbers
- Example
add(1, 114513); // 114514
add(1)(114513); // 114514add(1, 114513); // 114514
add(1)(114513); // 114514minus()
Calculates the difference between two numbers.
- Type
- Details
Takes two numbers
- Example
minus(114515, 1); // 114514
minus(114515)(1); // 114514minus(114515, 1); // 114514
minus(114515)(1); // 114514mul()
Calculates the product of two numbers.
- Type
- Details
Takes two numbers
- Example
mul(57257, 2); // 114514
mul(57257)(2); // 114514mul(57257, 2); // 114514
mul(57257)(2); // 114514div()
Calculates the quotient of two numbers.
- Type
- Details
Takes two numbers
- Example
div(229030, 2); // 114514
div(229030)(2); // 114514div(229030, 2); // 114514
div(229030)(2); // 114514divr()
Calculates the reversed quotient of two numbers.
- Type
- Details
Takes two numbers
- Example
divr(2, 229030); // 114514
divr(2)(229030); // 114514divr(2, 229030); // 114514
divr(2)(229030); // 114514mod()
Calculates the remainder of integer division.
- Type
- Details
Takes two integers
For modulo operation instead of remainder, use rema().
- Example
mod(114514, 1); // 0
mod(114514)(1); // 0mod(114514, 1); // 0
mod(114514)(1); // 0rema()
Calculates the modulo of integer division.
- Type
- Details
Takes two integers
For remainder operation instead of modulo, use mod().
- Example
rema(114514, 1); // 0
rema(114514)(1); // 0rema(114514, 1); // 0
rema(114514)(1); // 0power()
Calculates the power of a number.
- Type
- Details
Takes two numbers
- Example
power(114514, 1); // 114514
power(2)(3); // 8power(114514, 1); // 114514
power(2)(3); // 8negate()
Negates a number.
- Type
- Details
Takes a number as an argument; returns its negation.
- Example
negate(-114514); // 114514negate(-114514); // 114514upper()
Generates a descending comparator for use with the sort() function.
- Type
- Details
Returns a descending comparator for use with the sort function.
- Example
sort(upper(), [3, 2, 1]); // [3, 2, 1]sort(upper(), [3, 2, 1]); // [3, 2, 1]under()
Generates an ascending comparator for use with the sort() function.
- Type
- Details
Returns an ascending comparator for use with the sort function.
- Example
sort(under(), [3, 2, 1]); // [1, 2, 3]sort(under(), [3, 2, 1]); // [1, 2, 3]sort()
Sorts an array based on a specific rule.
- Type
- Details
Takes a rule function as the first argument and an array to be sorted as the second argument; returns a sorted array.
The rule function follows the same protocol as Array.prototype.sort.
- Example
sort(under(), [3, 2, 1]); // [1, 2, 3]sort(under(), [3, 2, 1]); // [1, 2, 3]median()
Calculates the median of an array of numbers.
- Type
- Details
Takes an array of numbers as an argument; returns its median.
- Example
median([1, 2, 3, 4, 5, 6]); // 3.5median([1, 2, 3, 4, 5, 6]); // 3.5sum()
Calculates the sum of an array of numbers.
- Type
- Details
Takes an array of numbers as an argument; returns the sum of all elements.
- Example
sum([1, 2, 3, 4, 5, 6]); // 21sum([1, 2, 3, 4, 5, 6]); // 21average()
Calculates the average of an array of numbers.
- Type
- Details
Takes an array of numbers as an argument; returns the average of all elements.
- Example
average([1, 2, 3, 4, 5, 6]); // 3.5average([1, 2, 3, 4, 5, 6]); // 3.5prod()
Calculates the product of an array of numbers.
- Type
- Details
Takes an array of numbers as an argument; returns the product of all elements.
- Example
prod([1, 2, 3, 4, 5, 6]); // 720prod([1, 2, 3, 4, 5, 6]); // 720max()
Finds the maximum number in an array.
- Type
- Details
Takes an array of numbers as an argument; returns the maximum number in the array.
- Example
max([1, 1, 4, 5, 1, 4]); // 5max([1, 1, 4, 5, 1, 4]); // 5min()
Finds the minimum number in an array.
- Type
- Details
Takes an array of numbers as an argument; returns the minimum number in the array.
- Example
min([1, 1, 4, 5, 1, 4]); // 1min([1, 1, 4, 5, 1, 4]); // 1dec()
Decrements a number.
- Type
- Details
Takes a number as an argument; returns the decremented value.
- Example
dec(114515); // 114514dec(114515); // 114514inc()
Increments a number.
- Type
- Details
Takes a number as an argument; returns the incremented value.
- Example
inc(114513); // 114514inc(114513); // 114514