Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Basic | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
__construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
frequency | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Math\Statistic |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Math\Statistic; |
16 | |
17 | /** |
18 | * Basic statistic functions. |
19 | * |
20 | * @package phpOMS\Math\Statistic |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | */ |
25 | final class Basic |
26 | { |
27 | /** |
28 | * Constructor. |
29 | * |
30 | * @since 1.0.0 |
31 | * @codeCoverageIgnore |
32 | */ |
33 | private function __construct() |
34 | { |
35 | } |
36 | |
37 | /** |
38 | * Calculate frequency. |
39 | * |
40 | * Example: ([4, 5, 9, 1, 3]) |
41 | * |
42 | * @param array<array|int|float> $values Values |
43 | * |
44 | * @return array<array|int|float> |
45 | * |
46 | * @since 1.0.0 |
47 | */ |
48 | public static function frequency(array $values) : array |
49 | { |
50 | $freaquency = []; |
51 | $sum = 1; |
52 | |
53 | if (!(\is_array(\reset($values)))) { |
54 | $sum = \array_sum($values); |
55 | } |
56 | |
57 | foreach ($values as $value) { |
58 | $freaquency[] = \is_array($value) ? self::frequency($value) : $value / $sum; |
59 | } |
60 | |
61 | return $freaquency; |
62 | } |
63 | } |