packages/optimizely-sdk/lib/core/condition_tree_evaluator/index.js
function evaluate(conditions, leafEvaluator) {
  if (Array.isArray(conditions)) {
    var firstOperator = conditions[0];
    var restOfConditions = conditions.slice(1);

    if (DEFAULT_OPERATOR_TYPES.indexOf(firstOperator) === -1) {
      // Operator to apply is not explicit - assume 'or'
      firstOperator = OR_CONDITION;
      restOfConditions = conditions;
    }

    switch (firstOperator) {
      case AND_CONDITION:
        return andEvaluator(restOfConditions, leafEvaluator);
      case NOT_CONDITION:
        return notEvaluator(restOfConditions, leafEvaluator);
      default: // firstOperator is OR_CONDITION
        return orEvaluator(restOfConditions, leafEvaluator);
    }
  }

  var leafCondition = conditions;
  return leafEvaluator(leafCondition);
}
function evaluate(conditions, leafEvaluator) {
  if (Array.isArray(conditions)) {
    var firstOperator = conditions[0];
    var restOfConditions = conditions.slice(1);

    if (DEFAULT_OPERATOR_TYPES.indexOf(firstOperator) === -1) {
      // Operator to apply is not explicit - assume 'or'
      firstOperator = OR_CONDITION;
      restOfConditions = conditions;
    }

    switch (firstOperator) {
      case AND_CONDITION:
        return andEvaluator(restOfConditions, leafEvaluator);
      case NOT_CONDITION:
        return notEvaluator(restOfConditions, leafEvaluator);
      default: // firstOperator is OR_CONDITION
        return orEvaluator(restOfConditions, leafEvaluator);
    }
  }

  var leafCondition = conditions;
  return leafEvaluator(leafCondition);
}
function evaluate ( conditions , leafEvaluator ) { if ( Array . isArray ( conditions ) ) { var firstOperator = conditions [ 0 ] ; var restOfConditions = conditions . slice ( 1 ) ; if ( DEFAULT_OPERATOR_TYPES . indexOf ( firstOperator ) === - 1 ) { // Operator to apply is not explicit - assume 'or' firstOperator = OR_CONDITION ; restOfConditions = conditions ; } switch ( firstOperator ) { case AND_CONDITION : return andEvaluator ( restOfConditions , leafEvaluator ) ; case NOT_CONDITION : return notEvaluator ( restOfConditions , leafEvaluator ) ; default : // firstOperator is OR_CONDITION return orEvaluator ( restOfConditions , leafEvaluator ) ; } } var leafCondition = conditions ; return leafEvaluator ( leafCondition ) ; }
Top level method to evaluate conditions
@param  {Array|*}    conditions      Nested array of and/or conditions, or a single leaf
condition value of any type
Example: ['and', '0', ['or', '1', '2']]
@param  {Function}   leafEvaluator   Function which will be called to evaluate leaf condition
values
@return {?Boolean}                   Result of evaluating the conditions using the operator
rules and the leaf evaluator. A return value of null
indicates that the conditions are invalid or unable to be
evaluated
Top level method to evaluate conditions