Skip to content

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
js
odd(114514); // false
odd(114514); // false

even() ​

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
js
even(114514); // true
even(114514); // true

add() ​

Calculates the sum of two numbers.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
add(1, 114513); // 114514
add(1)(114513); // 114514
add(1, 114513); // 114514
add(1)(114513); // 114514

minus() ​

Calculates the difference between two numbers.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
minus(114515, 1); // 114514
minus(114515)(1); // 114514
minus(114515, 1); // 114514
minus(114515)(1); // 114514

mul() ​

Calculates the product of two numbers.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
mul(57257, 2); // 114514
mul(57257)(2); // 114514
mul(57257, 2); // 114514
mul(57257)(2); // 114514

div() ​

Calculates the quotient of two numbers.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
div(229030, 2); // 114514
div(229030)(2); // 114514
div(229030, 2); // 114514
div(229030)(2); // 114514

divr() ​

Calculates the reversed quotient of two numbers.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
divr(2, 229030); // 114514
divr(2)(229030); // 114514
divr(2, 229030); // 114514
divr(2)(229030); // 114514

mod() ​

Calculates the remainder of integer division.

  • Type
  • Details

Takes two integers as arguments; returns .

For modulo operation instead of remainder, use rema().

  • Example
js
mod(114514, 1); // 0
mod(114514)(1); // 0
mod(114514, 1); // 0
mod(114514)(1); // 0

rema() ​

Calculates the modulo of integer division.

  • Type
  • Details

Takes two integers as arguments; returns .

For remainder operation instead of modulo, use mod().

  • Example
js
rema(114514, 1); // 0
rema(114514)(1); // 0
rema(114514, 1); // 0
rema(114514)(1); // 0

power() ​

Calculates the power of a number.

  • Type
  • Details

Takes two numbers as arguments; returns .

  • Example
js
power(114514, 1); // 114514
power(2)(3); // 8
power(114514, 1); // 114514
power(2)(3); // 8

negate() ​

Negates a number.

  • Type
  • Details

Takes a number as an argument; returns its negation.

  • Example
js
negate(-114514); // 114514
negate(-114514); // 114514

upper() ​

Generates a descending comparator for use with the sort() function.

  • Type
  • Details

Returns a descending comparator for use with the sort function.

  • Example
js
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
js
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
js
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
js
median([1, 2, 3, 4, 5, 6]); // 3.5
median([1, 2, 3, 4, 5, 6]); // 3.5

sum() ​

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
js
sum([1, 2, 3, 4, 5, 6]); // 21
sum([1, 2, 3, 4, 5, 6]); // 21

average() ​

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
js
average([1, 2, 3, 4, 5, 6]); // 3.5
average([1, 2, 3, 4, 5, 6]); // 3.5

prod() ​

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
js
prod([1, 2, 3, 4, 5, 6]); // 720
prod([1, 2, 3, 4, 5, 6]); // 720

max() ​

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
js
max([1, 1, 4, 5, 1, 4]); // 5
max([1, 1, 4, 5, 1, 4]); // 5

min() ​

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
js
min([1, 1, 4, 5, 1, 4]); // 1
min([1, 1, 4, 5, 1, 4]); // 1

dec() ​

Decrements a number.

  • Type
  • Details

Takes a number as an argument; returns the decremented value.

  • Example
js
dec(114515); // 114514
dec(114515); // 114514

inc() ​

Increments a number.

  • Type
  • Details

Takes a number as an argument; returns the incremented value.

  • Example
js
inc(114513); // 114514
inc(114513); // 114514

PureEval released under the GPL-3.0 License.