@param int[] $ages

@return float|int
19908
private function getAverageValue(array $ages)
    {
        $total = 0;

        foreach ($ages as $value) {
            $total = $total + $value;
        }

        return ($total / count($ages));
    }
506208
public function findAgeUnderVerification($age)
    {
        $ageUnderAttr = sprintf(self::AGE_UNDER_FORMAT, (int) $age);
        return $this->getAgeVerificationByAttribute($ageUnderAttr);
    }
625398
public function plusYears(int $years) : YearWeek
    {
        if ($years === 0) {
            return $this;
        }

        return $this->withYear($this->year + $years);
    }
883882
protected function aggregateValues(array $values)
    {
        $max = $values[0];

        foreach ($values as $value) {
            if ($value > $max) {
                $max = $value;
            }
        }

        return $max;
    }
914317
public static function divide(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $quotients        = array_map(
            function ($x) {
                return $x;
            },
            $arrays[0]
        );

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 1; $j < $number_of_arrays; $j++) {
                $quotients[$i] /= $arrays[$j][$i];
            }
        }

        return $quotients;
    }
656597
public static function min($array = false, $decimals = 3) {

        if($array && Validate::isArray($array)) {

            return self::round(min($array), $decimals);
        }

        return false;
    }
79653
private function ageBetweenSiblingsAge(int $total): string
    {
        $rows = $this->ageBetweenSiblingsQuery($total);

        foreach ($rows as $fam) {
            return $this->calculateAge((int) $fam->age);
        }

        return '';
    }
518525
public static function GetLowest ($array, $keys) {
		foreach ((array) $keys as $key) {
			if (isset($array[$key]) || array_key_exists($key, $array)) {
				$array = $array[$key];
			} else {
				return null;
			}
		}
		return $array;
	}
1201216
public function plusYears(int $years) : ZonedDateTime
    {
        return ZonedDateTime::of($this->localDateTime->plusYears($years), $this->timeZone);
    }
1152333
static function age($kdy) {
		$kdy = self::convert($kdy, self::INT);
		$stari=floor((time()-$kdy)/60);
		if ($stari<60) {$stari=$stari." ".Strings::plural($stari,"minuta","minuty","minut");}
		else {$stari=floor($stari/60);
			if ($stari>=24) {$stari=(floor($stari/24)); $stari.=" ".Strings::plural($stari,"den","dny","dnů");}
				else $stari=$stari." ".Strings::plural($stari,"hodina","hodiny","hodin");
		}
		if ($stari==-1 or $stari=="0 minut") $stari="úplně nové";
		return $stari;
	}
818589
private function freePercentCalculation(array $usedPercent = array()) {
        $aReturn = array();
        foreach ($usedPercent as $keyUsedPercent => $valueUsedPercent) {
            $aReturn[$keyUsedPercent] = ($valueUsedPercent > 0) ? (100 - $valueUsedPercent): 100;
        }
        return $aReturn;
    }
176044
public static function getAgeAtEvent(string $age_string): string
    {
        switch (strtoupper($age_string)) {
            case 'CHILD':
                return I18N::translate('Child');
            case 'INFANT':
                return I18N::translate('Infant');
            case 'STILLBORN':
                return I18N::translate('Stillborn');
            default:
                return preg_replace_callback(
                    [
                        '/(\d+)([ymwd])/',
                    ],
                    static function (array $match): string {
                        $num = (int) $match[1];

                        switch ($match[2]) {
                            case 'y':
                                return I18N::plural('%s year', '%s years', $num, I18N::number($num));
                            case 'm':
                                return I18N::plural('%s month', '%s months', $num, I18N::number($num));
                            case 'w':
                                return I18N::plural('%s week', '%s weeks', $num, I18N::number($num));
                            case 'd':
                                return I18N::plural('%s day', '%s days', $num, I18N::number($num));
                            default:
                                throw new LogicException('Should never get here');
                        }
                    },
                    $age_string
                );
        }
    }
868740
public static function average($array = false, $decimals = 2) {

        if($array && Validate::isArray($array)) {

            return self::round((array_sum($array) / count($array)), $decimals); 
        }

        return false;
    }
949779
protected function getFreshNormal($wheres)
    {
        $columns = [];

        // Convert select columns to simple projections.
        foreach ($this->columns as $column) {
            $columns[$column] = true;
        }

        // Add custom projections.
        if ($this->projections) {
            $columns = array_merge($columns, $this->projections);
        }
        $options = [];

        // Apply order, offset, limit and projection
        //if ($this->timeout) {
        //    $options['maxTimeMS'] = $this->timeout;
        //}
        if ($this->orders) {
            $options['sort'] = $this->compileOrders($this->orders);
        }
        if ($this->offset) {
            $options['skip'] = $this->offset;
        }
        if ($this->limit) {
            $options['limit'] = $this->limit;
        }
        if ($columns) {
            $options['projection'] = $columns;
        }
        // if ($this->hint)    $cursor->hint($this->hint);

        // Fix for legacy support, converts the results to arrays instead of objects.
        $options['typeMap'] = ['root' => 'array', 'document' => 'array'];

        // Add custom query options
        if (count($this->options)) {
            $options = array_merge($options, $this->options);
        }

        // Execute query and get MongoCursor
        $cursor = $this->collection->find($wheres, $options);

        // Return results as an array with numeric keys
        $results = iterator_to_array($cursor, false);

        return $results;
    }
1067021
public static function getCenturiesAgo($ago, $endDateTime = null)
    {
        return static::getDateTimeRange(
            Carbon::now()->subYears($ago * 100)->startOfCentury(),
            $endDateTime ?: Carbon::now()->subYears($ago * 100)->endOfCentury()
        );
    }
1082162
private function ageBetweenSiblingsQuery(int $total): array
    {
        $prefix = DB::connection()->getTablePrefix();

        return DB::table('link AS link1')
            ->join('link AS link2', static function (JoinClause $join): void {
                $join
                    ->on('link2.l_from', '=', 'link1.l_from')
                    ->on('link2.l_type', '=', 'link1.l_type')
                    ->on('link2.l_file', '=', 'link1.l_file');
            })
            ->join('dates AS child1', static function (JoinClause $join): void {
                $join
                    ->on('child1.d_gid', '=', 'link1.l_to')
                    ->on('child1.d_file', '=', 'link1.l_file')
                    ->where('child1.d_fact', '=', 'BIRT')
                    ->where('child1.d_julianday1', '<>', 0);
            })
            ->join('dates AS child2', static function (JoinClause $join): void {
                $join
                    ->on('child2.d_gid', '=', 'link2.l_to')
                    ->on('child2.d_file', '=', 'link2.l_file')
                    ->where('child2.d_fact', '=', 'BIRT')
                    ->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
            })
            ->where('link1.l_type', '=', 'CHIL')
            ->where('link1.l_file', '=', $this->tree->id())
            ->distinct()
            ->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
            ->orderBy('age', 'DESC')
            ->take($total)
            ->get()
            ->all();
    }
965371
public function getNextPosition(array $conditions): int
    {
        $columnName = $conditions['column'];

        $query = $this->connection->createQueryBuilder();
        $query->select($this->connection->getDatabasePlatform()->getMaxExpression($columnName) . ' AS ' . $columnName)
            ->from($conditions['table']);

        $this->applyConditions($query, $conditions['conditions']);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return (int) ($data[0][$columnName] ?? -1) + 1;
    }