| Conditions | 7 |
| Paths | 15 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function highFive(array $items): array |
||
| 10 | { |
||
| 11 | if (empty($items)) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | $map = []; |
||
| 15 | foreach ($items as $item) { |
||
| 16 | [$sid, $score] = $item; |
||
| 17 | $scores = $map[$sid] ?? array_fill(0, 5, 0); |
||
| 18 | $j = 0; |
||
| 19 | for ($i = 1; $i < 5; $i++) { |
||
| 20 | if ($scores[$i] < $scores[$j]) { |
||
| 21 | $j = $i; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | if ($score > $scores[$j]) { |
||
| 25 | $scores[$j] = $score; |
||
| 26 | } |
||
| 27 | $map[$sid] = $scores; |
||
| 28 | } |
||
| 29 | [$ans, $keys] = [[], array_keys($map)]; |
||
| 30 | sort($keys); |
||
| 31 | foreach ($keys as $sid) { |
||
| 32 | $sum = (int) (array_sum($map[$sid]) / 5); |
||
| 33 | array_push($ans, [$sid, $sum]); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $ans; |
||
| 37 | } |
||
| 39 |