Class: BooleanExpression

BooleanExpression(items, type)

This class defines a boolean expression, which is a collection of items grouped together by "and"/"or" statements. For example, (("X > 5" or "X < 2") and "Y = 10").

Constructor

new BooleanExpression(items, type)

Parameters:
Name Type Description
items Array.<any> The items in the boolean expression. Each item can either be an object of an arbitrary type or a boolean expression.
type string The type of the boolean expression ('and'/'or');
Source:

Methods

evaluate(options) → {boolean}

Parameters:
Name Type Description
options object The options for evaluation.
Properties
Name Type Description
isItemTrue function A function that takes an argument that is an item in the boolean expression. The function returns whether the given item is true or false.
Source:
Returns:
Whether the overall expression is true or false.
Type
boolean

isAnd() → {boolean}

Source:
Returns:
Whether the expression is an 'and' expression.
Type
boolean

isOr() → {boolean}

Source:
Returns:
Whether the expression is an 'or' expression.
Type
boolean

reduce(options) → {any}

Parameters:
Name Type Description
options object The options for reduction.
Properties
Name Type Description
andInitialValue any The initial value for an expression with the 'and' type.
andReducer function A function that takes an object with three keys: `accumulator` (the accumulated value for the current expression), `item` (the current item), and `isReduced` (whether the current item is a nested boolean expression that has already been reduced). This function is only used for expressions that have the 'and' type.
orInitialValue any The initial value for an expression with the 'or' type.
orReducer function A function that takes an object with three keys: `accumulator` (the accumulated value for the current expression), `item` (the current item), and `isReduced` (whether the current item is a nested boolean expression that has already been reduced). This function is only used for expressions that have the 'or' type.
Source:
Returns:
The reduced value of the expression.
Type
any

simplify(options) → {BooleanExpression}

Parameters:
Name Type Description
options object The options for simplification.
Properties
Name Type Description
implies function A function that takes two arguments that are both items in the boolean expression. The function returns whether the first item being true implies that the second item is true. For example, "X > 5" would imply "X > 3".
Source:
Returns:
The simplified boolean expression.
Type
BooleanExpression

(static) and(…items) → {BooleanExpression}

Constructs a new boolean expression with the 'and' type.
Parameters:
Name Type Attributes Description
items any <repeatable>
The items in the boolean expression. Each item can either be an object of an arbitrary type or a boolean expression.
Source:
Returns:
The new boolean expression.
Type
BooleanExpression

(static) or(…items) → {BooleanExpression}

Constructs a new boolean expression with the 'or' type.
Parameters:
Name Type Attributes Description
items any <repeatable>
The items in the boolean expression. Each item can either be an object of an arbitrary type or a boolean expression.
Source:
Returns:
The new boolean expression.
Type
BooleanExpression