Factory method, ensures unique rules
@param mixed scalar non-terminal symbol
@param array list of symbols in right hand side
@return array
167894
function make_rule( $nt, array $rhs ){
		
		if( ! isset($this->uindex) || ! isset($this->ntindex) ){
			$this->rebuild_index();
		}
		
		// explicit goal rule ??
		if( end($rhs) === P_EOF ){
			// trigger_error("Do not specify P_EOF explicitly in grammar", E_USER_WARNING );
			$this->goal = $nt;
			$this->rules[ -2 ] = array( P_GOAL, array( $nt ) );
			$this->rebuild_index();
		}
		// guess start symbol as first in grammar
		else if( is_null( $this->start_symbol() ) ){
			$this->start_symbol( $nt );
		}
		
		reset( $rhs );
		$sig = self::rule_signature( $nt, $rhs );
		
		// return existing if possible
		if( isset($this->uindex[$sig]) ){
			return $this->rules[ $this->uindex[$sig] ];
		}
		// else create new rule
		$rule = array( $nt, $rhs );
	
		// register globally
		$this->rules[ $this->i ] = $rule;
		$this->uindex[$sig] = $this->i;
		$this->ntindex[$nt][] = $this->i;
		$this->i += 2;
	
		// register symbols
		if( isset($this->ts[$nt] ) ){
			// not terminal after all
			unset( $this->ts[$nt] );
		}
		$this->nts[ $nt ] = $nt;
		// assume rhs all terminals until identified as not
		foreach( $rhs as $s ){
			is_array( $s ) and $s = $s[0];
			if( !isset($this->nts[$s]) ){
				$this->ts[ $s ] = $s;
			}
		}
		return $rule;
	}
1071530
public function uniqueKeepIndex(): self
    {
        // INFO: \array_unique() can't handle e.g. "stdClass"-values in an array

        // init
        $array = $this->getArray();

        $this->array = \array_reduce(
            \array_keys($array),
            static function ($resultArray, $key) use ($array) {
                if (!\in_array($array[$key], $resultArray, true)) {
                    $resultArray[$key] = $array[$key];
                }

                return $resultArray;
            },
            []
        );
        $this->generator = null;

        if ($this->array === null) {
            $this->array = [];
        } else {
            $this->array = (array) $this->array;
        }

        return $this;
    }
308004
public static function factory(array $data = []): self
    {
        $type = $data['type'];
        // fix for php7 reserved name (scalar type hint)
        if ('number' === $type) {
            $type = 'numbr';
        }

        /** @var Node $class */
        $class = 'Gdbots\QueryParser\Node\\' . StringUtils::toCamelFromSnake($type);
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Node type [%s] does not exist.', $type));
        }

        return $class::fromArray($data);
    }
61242
protected function createBuilder($array = [])
    {
        $builder = $this->model->newQuery();

        if ( ! empty($array)) {
            $builder->where($array);
        }

        if ( ! empty($this->scopes)) {
            foreach ($this->scopes as $scope => $args) {
                $builder->{$scope}($args);
            }
        }

        return $builder;
    }
325657
public static String[] unique(String[] arrays) {
        List<String> list = new ArrayList<>(arrays.length);
        for (String arr : arrays) {
            if (!list.contains(arr)) {
                list.add(arr);
            }
        }
        String[] res = new String[list.size()];
        int i = 0;
        for (String arr : list) {
            res[i++] = arr;
        }
        return res;
    }
1247269
static function fetchRepeatMemberInArray( $array )
	{
		$arrRepeat = [];
		$length = count( $array );
		for ( $i = 0; $i < $length; $i++ ) { 
			for ( $j = $i + 1; $j < $length; $j++ ) { 
				if ( $array[$i] == $array[$j] ) {
					$arrRepeat[] = $array[$i];
				}
			}
		}

		return $arrRepeat;
	}
342537
function uniqueArray(arr) {
  var result = [];

  for (var i = 0; i < arr.length; i++) {
    if (result.indexOf(arr[i]) === -1) {
      result.push(arr[i]);
    }
  }

  return result;
}
374384
public static function array_unique($array)
    {
        $keys = array_keys($array);
        $toDrop = array();
        for ($i = count($keys) - 1; $i >=0 ; $i-- ) {
            for ($j = $i - 1; $j >=0 ; $j--) {
                if ($array[$keys[$i]]->__equals($array[$keys[$j]])) {
                    $toDrop[] = $keys[$i];
                    break;
                }
            }
        }
        foreach ($toDrop as $key) {
            unset($array[$key]);
        }
        return $array;
    }
891537
public function validateUniques(array $rules = array(), array $customMessages = array()) {
		$rules = $this->buildUniqueExclusionRules($rules);
		return $this->validate($rules, $customMessages);
	}
346476
protected function buildConstraints($values)
    {
        if (is_array($values)) {
            $constraints = [];
            foreach ($values as $value) {
                $constraints[] = Constraint::make($value);
            }
            return $constraints;
        } else {
            return Constraint::make($values);
        }
    }
42542
public static function arrayUnflattenDotNotation($array, $separator = '.')
    {
        $newArray = [];
        foreach ($array as $key => $value) {
            $dots = explode($separator, $key);
            if (\count($dots) > 1) {
                $last = &$newArray[$dots[0]];
                foreach ($dots as $k => $dot) {
                    if ($k === 0) {
                        continue;
                    }
                    $last = &$last[$dot];
                }
                $last = $value;
            } else {
                $newArray[$key] = $value;
            }
        }

        return $newArray;
    }
1185599
public function rewrite_rules_array( array $rules ){
	    if( !empty($this->classes) ){
            // Normal rewrite rules
            $new_rewrite = [];
            $error_message = [];
            foreach( $this->classes as $class_name ){
                $prefix = $this->get_prefix($class_name);
                /** @var RestBase $class_name */
                if( empty($prefix) ){
                    $error_message[] = sprintf($this->__('<code>%s</code> should have prefix property.'), $class_name);
                    continue;
                }
                // API Rewrite rules
                $new_rewrite[trim($prefix, '/').'(/.*)?$'] = "index.php?{$this->api_class}={$class_name}&{$this->api_vars}=\$matches[1]";
            }
            if( !empty($new_rewrite) ){
                $rules = array_merge($new_rewrite, $rules);
            }
            if( !empty($error_message) ){
                add_action('admin_notices', function() use ($error_message) {
                    printf('<div class="error"><p>%s</p></div>', implode('<br />', $error_message));
                });
            }
        }
        return $rules;
    }
194777
public static function extractFromArray($value)
    {
        /**
         * @param array $filters
         *
         * @return array
         */
        $extractVoters = function (array $filters) {
            $voters = [];
            foreach ($filters as $filter) {
                if (is_array($filter)) {
                    $voters = array_merge($voters, array_keys($filter));
                }
            }

            return array_unique($voters);
        };

        $voters = [];
        if (isset($value['filters'])) {
            $voters = array_merge($voters, $extractVoters($value['filters']));
        }
        if (isset($value['breaker'])) {
            $voters = array_merge($voters, $extractVoters($value['breaker']));
        }
        if (isset($value['values'])) {
            foreach ($value['values'] as $valueValue) {
                if (isset($valueValue['filters'])) {
                    $voters = array_merge($voters, $extractVoters($valueValue['filters']));
                }
            }
        }

        return array_values(array_unique($voters));
    }
1300210
public function generateRules($index)
    {
        $types = [];
        foreach ($index->columns as $column) {
            if ($column->isMva) {
                $types['safe'][] = $column->name;
                continue;
            }
            if ($column->isPrimaryKey) {
                $types['required'][] = $column->name;
                $types['unique'][] = $column->name;
            }
            switch ($column->type) {
                case Schema::TYPE_PK:
                case Schema::TYPE_INTEGER:
                case Schema::TYPE_BIGINT:
                    $types['integer'][] = $column->name;
                    break;
                case Schema::TYPE_BOOLEAN:
                    $types['boolean'][] = $column->name;
                    break;
                case Schema::TYPE_FLOAT:
                    $types['number'][] = $column->name;
                    break;
                case Schema::TYPE_TIMESTAMP:
                    $types['safe'][] = $column->name;
                    break;
                default: // strings
                    $types['string'][] = $column->name;
            }
        }
        $rules = [];
        foreach ($types as $type => $columns) {
            $rules[] = "[['" . implode("', '", $columns) . "'], '$type']";
        }

        return $rules;
    }
1179318
public function regex($array = [])
    {
        $filtered = [];
        foreach ($array as $key => $value) {
            if ($this->isRegex($key)) {
                $filtered[$key] = $value;
            }
        }

        return $filtered;
    }
760914
private static function prepareRules(array $rules)
    {
        $mergedRules = [];

        foreach ($rules as $ruleFields => $ruleConditions) {

            //if set of fields like 'firstname, lastname...'
            if (strpos($ruleFields, ',') !== false) {
                foreach (explode(',', $ruleFields) as $fieldName) {
                    $fieldName = trim($fieldName);

                    if (!isset($mergedRules[$fieldName])) {
                        $mergedRules[$fieldName] = $ruleConditions;
                    } else {
                        $mergedRules[$fieldName] .= '|'.$ruleConditions;
                    }
                }
            } else {
                if (!isset($mergedRules[$ruleFields])) {
                    $mergedRules[$ruleFields] = $ruleConditions;
                } else {
                    $mergedRules[$ruleFields] .= '|'.$ruleConditions;
                }
            }
        }

        $finalRules = [];

        //remove duplicated rules, like 'required|alpha|required'
        foreach ($mergedRules as $newRule => $rule) {
            $finalRules[$newRule] = implode('|', array_unique(explode('|', $rule)));
        }

        return $finalRules;
    }
1027181
function customUnique(array) {
  const unique = uniqBy(array, 'fname');
  // we construct unique portlets array will all linked categories (reversing category and portlets child)
  unique.forEach((elem) => {
    const dupl = array.filter((e) => e.fname === elem.fname);
    const allCategories = dupl.flatMap(({categories}) => categories);
    elem.categories = [...new Set(allCategories)];
  });
  return unique;
}