Additional functions to use in dynamic variables

In advanced actions, you can use custom functions in addition to functions based on MathJS:

String Functions

indexOf(haystack, needle)

If the “needle” string is found in the “haystack” string or list, the function returns its (zero-based) position, otherwise it evaluates to -1.

Examples:
 indexOf("ABCD", "A") //returns 0
 indexOf("ABCD", "CD") //returns 2
 indexOf("ABCD", "E") //returns -1
 indexOf(["a","b","c"], "a") //returns 0
 indexOf(["a","b","c"], "bc") //returns -1

getIndexValue(haystack, index)

If the “index” number is smaller than the “haystack” list, the function returns the value located at the “index” position, otherwise it will error.

Examples:
 getIndexValue(["a","b","c"], 0) //returns a
 getIndexValue(["a","b","c"], 1) //returns b

substr(string, start[, length])

This function returns a substring of the original string, starting from the zero-based start position. If length is specified, it returns that many characters, and otherwise, it returns the rest of the string.

Examples:
 substr("ABCD", 1) //returns "BCD"
 substr("ABCD", 2, 1) //returns "C"
 substr("ABCD", 5) //returns ""

slice(string, start[, end])

This function returns a substring of the original string, starting from the zero-based start position. If an end position is provided, it returns all characters up to, but not including, the character at that position. Otherwise, it returns the rest of the string.

Negative positions for start or end are counted from the right side of the string.

Examples:
 slice("ABCD", 1) //returns "BCD"
 slice("ABCD", 0, 2) //returns "AB"
 slice("ABCD", 1, -1) //returns "BC"
 slice("ABCD", 2, 1) //returns ""

upper(string)

This function returns the provided string, converted to uppercase.

Example:
upper("aBcD") //returns "ABCD"

lower(string)

This function returns the provided string, converted to lowercase.

Example:
lower("aBcD") //returns "abcd"

length(string)

This function returns the length of the string.

Examples:
 length("") //returns 0
 length("ABCD") //returns 4

Logical functions

equal(value1, value2)

This function returns true if value1 and value2 are the same value and type, or otherwise, false. Alternative syntax for `value1 === value2`. (`value1 == value2` is a weaker comparison)

Examples:
 equal(2, 1) //returns false
 equal(1, 1) //returns true
 equal(1, "1") //returns false (different types)

ifElse(condition, valueIfTrue, valueIfFalse)

This function checks the provided condition. If the condition is true (or truthy), it returns the valueIfTrue, otherwise it returns the valueIfFalse.

Examples:
 ifElse(equal(1, 5), "equal", "not equal") //returns "not equal"
 ifElse(equal(2, 2), "equal", "not equal") //returns "equal"