Nodes: Data Expression
Intuitive maths-oriented expressions for data manipulation.
Introduction
The Nodes: Data Expression feature in Ligantic provides a powerful and flexible way to manipulate data using intuitive, math-oriented expressions. This feature allows you to perform a wide range of data transformations and calculations directly within your Ligantic workflows, without the need for complex programming or scripting.
Expression Syntax
The expression syntax used in Nodes: Data Expression is similar to normal JavaScript expressions, but is more math-oriented.
Operators
In addition to the standard arithmetic operators, Nodes: Data Expression also includes a number of unary operators that can be used to perform various mathematical and logical operations. These include:
-x: Negation+x: Unary plus (converts the operand to a number, but has no other effect)x!: Factorialabs x: Absolute value (magnitude) of xacos x: Arc cosine of x (in radians)acosh x: Hyperbolic arc cosine of x (in radians)asin x: Arc sine of x (in radians)asinh x: Hyperbolic arc sine of x (in radians)atan x: Arc tangent of x (in radians)atanh x: Hyperbolic arc tangent of x (in radians)cbrt x: Cube root of xceil x: Ceiling of x — the smallest integer that's >= xcos x: Cosine of x (x is in radians)cosh x: Hyperbolic cosine of x (x is in radians)exp x: e^x (exponential/antilogarithm function with base e)expm1 x: e^x - 1floor x: Floor of x — the largest integer that's <= xlength x: String or array length of xln x: Natural logarithm of xlog x: Natural logarithm of x (synonym forln, not base-10)log10 x: Base-10 logarithm of xlog2 x: Base-2 logarithm of xlog1p x: Natural logarithm of (1 + x)not x: Logical NOT operatorround x: X, rounded to the nearest integer, using "grade-school rounding"sign x: Sign of x (-1, 0, or 1 for negative, zero, or positive respectively)sin x: Sine of x (x is in radians)sinh x: Hyperbolic sine of x (x is in radians)sqrt x: Square root of x. Result is NaN (Not a Number) if x is negative.tan x: Tangent of x (x is in radians)tanh x: Hyperbolic tangent of x (x is in radians)trunc x: Integral part of a X, looks likefloor(x)unless for negative number
Functions
In addition to the built-in operators, Nodes: Data Expression also includes a number of pre-defined functions that can be used to perform various data manipulation and analysis tasks. These include:
random(n): Get a random number in the range[0, n). Ifnis zero, or not provided, it defaults to 1.min(a,b,...): Get the smallest (minimum) number in the list.max(a,b,...): Get the largest (maximum) number in the list.hypot(a,b): Hypotenuse, i.e. the square root of the sum of squares of its arguments.pyt(a, b): Alias forhypot.pow(x, y): Equivalent tox^y.atan2(y, x): Arc tangent ofx/y. i.e. the angle between(0, 0)and(x, y)in radians.roundTo(x, n): Roundsxtonplaces after the decimal point.map(f, a): Array map: Pass each element ofathe functionf, and return an array of the results.fold(f, y, a): Array fold: Fold/reduce arrayainto a single value,yby settingy = f(y, x, index)for each elementxof the array.filter(f, a): Array filter: Return an array containing only the values fromawheref(x, index)is true.indexOf(x, a): Return the first index of string or arrayamatching the valuex, or-1if not found.join(sep, a): Concatenate the elements ofa, separated bysep.if(c, a, b): Function form ofc ? a : b. Note: This always evaluates bothaandb, regardless of whethercis true or not. Usec ? a : binstead if there are side effects, or if evaluating the branches could be expensive.addDuration(dateTime, durationValue, durationUnit): Add a duration to a given date and time.dateTime: The starting datetime value.durationValue: The numeric value of the duration to add.durationUnit: The unit of the duration - supported values:hours,minutes,seconds.
slice(stringOrArray, start, end): Extract a portion of a string or array.stringOrArrayLink: The input string or array to slice.start: The starting index of the slice (inclusive).end: The optional ending index of the slice (exclusive).
startsWith(string, testString, start)- Tests whether a string begins with the characters of another string.
- Parameters:
string: The main string to checktestString: The sequence of characters to search for at the beginning of the main stringstart(optional): The position in the main string at which to begin searching. If omitted, the search starts from index 0
- Returns:
trueif the main string begins withtestStringat the specified positionfalseotherwise
- Examples:
startsWith("Hello World", "Hello")returns truestartsWith("Hello World", "World", 6)returns truestartsWith("Hello World", "World")returns false
Constants
Nodes: Data Expression also includes a number of pre-defined constants that can be used in expressions, including:
E: The value of e (mathematical constant), equal toexp 1PI: The value of π (mathematical constant)true: Logical true valuefalse: Logical false value
Use Cases
The Nodes: Data Expression feature in Ligantic can be used for a wide variety of data manipulation and analysis tasks, including:
- Performing mathematical calculations: You can use the various arithmetic and mathematical operators and functions to perform complex calculations on your data.
- Transforming data: You can use the expression syntax to transform data in various ways, such as filtering, mapping, and reducing arrays.
- Conditional logic: You can use the ternary operator and logical operators to implement conditional logic in your data processing workflows.
Overall, the Nodes: Data Expression feature provides a powerful and flexible way to work with data within the Ligantic platform, allowing you to perform a wide range of data manipulation and analysis tasks without the need for complex programming or scripting.