-
Notifications
You must be signed in to change notification settings - Fork 1
Default functions
This is a list of all default functions you can use in Reject.
-
[argument]
means an optional argument.
abs(x)
If x is a number, returns the absolute value. If x is a collection, returns the collection length. If x is a complex number, returns the length of the complex number.
abs(-10) # returns 10
abs([1, 2, 3]) # returns 3
abs(z(4, 3)) # returns 5
append(coll, item)
Appends an item to the back of collection coll. Returns the updated collection.
append([1, 2, 3], 4) # returns [1, 2, 3, 4]
arccot(x, [radian])
Returns the arc cotangent of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
arccot(1, true)
arccos(x, [radian])
Returns the arc cosine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
arccos(1)
arcsin(x, [radian])
Returns the arc sine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
arcsin(1)
arctan(x, [radian])
Returns the arc tangent of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
arctan(1)
ceil(x)
Returns x rounded upwards to the nearest integer.
ceil(1.4) # returns 2
cot(x, [radian])
Returns the cotangent of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
cot(1)
cot(90, false)
cos(x, [radian])
Returns the cosine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
cos(2 * pi)
cos(90, false) # returns 0
cosh(x, [radian])
Returns the hyperbolic cosine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
cosh(1)
deg(x)
Returns x in degrees.
deg(pi) # returns 180
det(x)
Returns the determinant value of matrix x.
det({{1, 2}, {3, 4}})
discriminant(a, b, c)
Returns the discriminant ((b ^ 2) - (4 * a * c)
).
discriminant(1, 3, 4)
even(x)
Returns true when x is even, false if not.
even(2) # returns true
even(3) # returns false
exp(x, [n])
If n is not present, returns x to the power of e (e^n
). If n is present, returns the result of x to the power of n (x^n
).
exp(2) # returns e^2
exp(2, 2) # returns 4
filter(pred, coll)
Selects all items from coll where pred returns true.
filter(:(x): even(x), range(0, 10)) # returns [0, 2, 4, 6, 8]
floor(x)
Returns x rounded downwards to the nearest integer.
floor(1.7) # returns 1
gcd(x, y)
Returns the greatest common denominator between two numbers.
gcd(5, 3)
get(coll, index)
Gets the item at index index from collection coll. Returns false if there is no value.
get([1, 2, 3], 1) # returns 2
insert(coll, index, item)
Inserts the specified item at index of coll. Returns the updated collection.
insert([1, 2, 3], 0, 4) # returns [4, 1, 2, 3]
lcm(x, y)
Returns the least common multiple of x and y.
lcm(5, 3) # returns 15
ln(x)
Returns the natural logarithm of x.
ln(1) # returns 0
log(x, [base])
Returns the logarithm of x. If base is not provided, base 10 is used by default.
log(1) # returns 0
map(afn, coll)
Returns the result of applying afn to all items in coll.
map(:(x): x + 1, [1, 2, 3]) # returns [2, 3, 4]
max(numbers)
Returns the biggest number provided.
max(1, 2, 3, 4, 5, 6) # returns 6
min(numbers)
Returns the smallest number provided.
min(1, 2, 3, 4, 5, 6) # returns 1
mod(number, divisor)
Returns the modulo between number and divisor.
mod(6, 3) # returns 0
not(x)
Returns the opposite logical value of x.
not(true) # returns false
not(not(true)) # returns true
num(x)
Parses x as a number.
num("1.5") # returns 3/2
num("1") # returns 1/1
plot_functions(l, r, dx, afn)
Plots the provided anonymous functions from the left bound to the right bound (both inclusive) with a specified step of dx.
plot_functions(pi, 2 * pi, 0.01, :(x): cos(x), :(x): sin(x))
plot_line(values)
Plots a line with the provided values. The x-axis will count from 0 by increments of 1. The values will be used as the y value.
plot_line([1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1])
print(xs)
Prints the concatenation of the arguments' string form, separated by a space.
print(1, 2, 3, "hey") # prints "1 2 3 hey"
poly2(a, b, c)
Returns the real results of the quadratic polynomial with the provided coefficients. Throws an error if the discriminant is less than 0. If there are 2 answers, returns a collection of size 2 with the answers.
poly2(6, 3, 2)
rad(x)
Returns x in radians.
rad(180) # returns pi
range(lower, upper, [increment])
Returns a collection of all numbers between the lower (inclusive) and upper (exclusive) bound. If increment is not specified, uses 1 as the step between numbers.
range(1, 3) # returns [1, 2]
range(1, 3, 0.5) # returns [1, 1.5, 2, 2.5]
reduce(afn, initialValue, coll)
Returns the result of applying afn to the initialValue and the first item in coll, then applying afn to that value and the second item in coll, until coll is exhausted.
reduce(:(x, y): x + y, 0, [1, 2, 3]) # returns 6
repeat(x, n)
Returns a collection of n, repeated x times.
repeat("hi", 3) # returns ["hi", "hi", "hi"]
repeat(3, 3) # returns [3, 3, 3]
root(x, n)
Returns the nth power root of x.
root(8, 3) # returns 2
set(coll, index, value)
Sets the value of coll at index to value. Returns the updated collection.
set([1, 2, 3], 0, 2) # returns [2, 2, 3]
sgn(x)
Returns the sign of x.
sgn(1) # returns 1
sgn(-1) # returns -1
sgn(-10) # returns -1
sgn(10) # returns 1
sin(x, [radian])
Returns the sine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
sin(pi) # returns 0
sinh(x, [radian])
Returns the hyperbolic sine of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
sinh(-1)
sqrt(x)
Returns the square root of x.
sqrt(4) # returns 2
str(xs)
Returns the concatenation of the provided arguments in their string form.
str("hey", "ho ", 2, 3, [1, 2]) # returns "heyho 23[1,2]"
sum(xs)
Returns the sum of all provided numbers.
sum(1, 2, 3, 4, 5) # returns 15
tan(x, [radian])
Returns the tangent of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
tan(10)
tanh(x, [radian])
Returns the hyperbolic tangent of x. If argument radian is not provided or set to true, will return the answer in radians. If false, will return the answer in degrees.
tanh(1)
uneven(x)
Returns true when x is uneven, false if not.
uneven(3) # returns true
uneven(4) # returns false
z(real, imaginary)
Returns a complex number with the provided real and imaginary values.
z(1, 1) # returns 1 + i
z(2, 2) # returns 2 + 2i