length

Return the length of an object

length
Parameters
x (any) A JavaScript object.
Returns
number: An integer.
Example
// returns 0
length(null)
length(undefined)
// returns 1
length(123)
length("abcd")
length(true)
// returns 2
length([1, 2])
length({x:-999, y:999})

which

Returns the indices of the true elements in an array

which
Parameters
x (Array) An array of booleans.
Returns
Array: An array of indices.
Example
// returns [0, 2]
which([true, false, true])

seq

Generates an arithmetic sequence of number.

seq
Parameters
from (number) A number; the starting value.
to (number) A number; the (maximal) ending value.
by (number) A number; increment of the sequence.
length_out (number) A non-negative integer; the desired output length.
Returns
Array: An array of numbers.
Example
// returns [1, 2, 3]
seq(1, 3)
// returns [2, 4, 6, 8, 10]
seq(2, 10, 2)
// returns [0, 2.5, 5, 7.5, 10]
seq(0, 10, null, 5)

rep

Replicate elements

rep
Parameters
x ((number | Array)) A number or a JavaScript Array; the element to replicate.
times ((number | Array)) A number; the number of times to replicate. If x is an array, then times can also be an array of the same size stating the the number of replications for each item in x.
Returns
any: A JavaScript Array
Example
// returns [1,1,1]
rep(1, 3)
// returns [1,2,1,2,1,2]
rep([1,2], 3)
// returns [1,1,2,2,2,2]
rep([1,2], [2,4])

dbinom

The Binomial distribution (PDF)

dbinom
Parameters
x ((number | Array)) The vector of quantiles.
size ((number | Array)) The number of trials.
prob ((number | Array)) The probability of success.
log (boolean = false) Whether the log value is returned.

pbinom

The Binomial distribution (CDF)

pbinom
Parameters
q ((number | Array)) The vector of quantiles.
size ((number | Array)) The number of trials.
prob ((number | Array)) The probability of success.
lower_tail (boolean = true) Whether the lower (or upper) tail is returned.
log_p (any = false)
log (boolean) Whether the log value is returned.

qbinom

The Binomial distribution (Quantile)

qbinom
Parameters
p ((number | Array)) The vector of probabilities.
size ((number | Array)) The number of trials.
prob ((number | Array)) The probability of success.
lower_tail (boolean = true) Whether the lower (or upper) tail is returned.
log_p (any = false)
log (boolean) Whether the log value is returned.

rbinom

The Binomial distribution (Sampling)

rbinom
Parameters
n (number) The number of samples.
size ((number | Array)) The number of trials.
prob ((number | Array)) The probability of success.

formalArgs

Return the name of the function arguments.

formalArgs
Parameters
func (function) A function.
Returns
any: A character array.
Example
function max(a, b) {
    return a > b ? a : b;
}
// returns ['a', 'b']
formalArgs(max)

ddist

A "factory" for density functions The function extends the function by the argument log.

ddist
Parameters
f (function) A function that performs the density calculation.

pdist

A "factory" for cumulative density functions (CDF) The function extends the function by the arguments lower_tail and log_p.

pdist
Parameters
f (function) A function that performs the CDF calculation.

qdist

A "factory" for quantile functions (CDF) The function extends the function by the arguments lower_tail and log_p. The first argument of the function must be the probability at which the quantile is seeked.

qdist
Parameters
f (function) A function that performs the quantile calculation.

digamma

The digamma function

digamma
Parameters
x ((boolean | number | Array)) The input. Numbers should be non-negative. true / false are converted into 1 / 0 before proceeding.
Returns
any: A number or an Array of numbers.

trigamma

The trigamma function

trigamma
Parameters
x ((boolean | number | Array)) The input. Numbers should be non-negative. true / false are converted into 1 / 0 before proceeding.
Returns
any: A number or an Array of numbers.

range

Return the range of an object.

range
Parameters
x ((boolean | number | Array)) The input.
Returns
Array: A 2-element Array containing the minimum and the maximum.
Example
range( 1 )             # [1,1]
range([ 1,2,3 ])       # [1,3]
range([ 1,2,[3,4] ])   # [1,4]

all2

Check if all values are true.

all2
Parameters
xs (Array) The input.
Returns
boolean: true or false; whether all vallues are true.
Example
all([true, true, false])  # false

any2

Check if any value is true.

any2
Parameters
xs (Array) The input.
Returns
boolean: true or false; whether there is a true value.
Example
any([true, true, false])  # true

ingamma0

Compute incomplete gamma functions

ingamma0(A: number, X: number): any
Parameters
A (number) A positive real number. (A LEQ 170)
X (number) A real number.
Returns
any: A triplet {GIN, GIM, GIP}, where GIN(A, X) := \int_0^x { t^{a - 1} exp(-t) } dt GIM(A, X) := Gamma(A) - GIN(A, X) = \int_x^{\infty} { t^{a - 1} exp(-t) } dt GIP(A, X) := GIN(A, X) / Gamma(A)

union

The union of two sets

union
Parameters
x (Array) A set; an array of elements.
y (Array) A set; aA set; an array of elements.
Returns
any: An array of elements.

intersect

The intersection of two sets

intersect
Parameters
x (Array) A set; an array of elements.
y (Array) A set; an array of elements.
Returns
any: An array of elements.

setdiff

The difference of two sets

setdiff
Parameters
x (Array) A set; an array of elements.
y (Array) A set; an array of elements.
Returns
any: An array of elements.

setequal

Equality of two sets

setequal
Parameters
x (Array) A set; an array of elements.
y (Array) A set; an array of elements.
Returns
boolean: true or false.

is_element

Check if an element belongs to a set

is_element
Parameters
x (any) An element, or an array of elements.
y (Array) A set; an array of elements.
Returns
any: An array of elements.

setsymdiff

The symmetric difference of two sets

setsymdiff
Parameters
x (Array) An array of elements.
y (Array) An array of elements.
Returns
any: An array of elements.

walk

A map function for nested Arrays.

walk
Parameters
x (Array) An Array (or a nested Array).
f (function) A function.
Returns
any: An Array (or a nested Array).
Example
walk([ 1, [2,3], [4,5] ], x => x + 1)  // returns [ 2, [ 3, 4 ], [ 5, 6 ] ]

first

Return the first element of an object

first
Parameters
x (any) A JavaScript object.
Returns
any: The first element of an object.

c

Combine values into a vector.

(Note that the function does not check that the elements are of the same type. Users should enforce such constraint by themselves.)

c(x: ...(number | character | boolean | Array)): Array
Parameters
x (...(number | character | boolean | Array)) Any number of values to be combined into a vector.
Returns
Array: A JavaScript Array; the combined "vector".
Example
// returns [1, 2, 3]
c(1, 2, 3)
// returns [1, 2, 3, 4]
c(1, 2, c(3, 4))
// returns ["a", "b", "c"]
c("a", "b", "c")