| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public static function sortArrayByParity2(array $arr): array |
||
| 26 | { |
||
| 27 | if (empty($arr)) { |
||
| 28 | return []; |
||
| 29 | } |
||
| 30 | $n = count($arr); |
||
| 31 | [$res, $start, $end] = [array_fill(0, $n, 0), 0, $n - 1]; |
||
| 32 | for ($i = 0; $i < $n; $i++) { |
||
| 33 | if ($arr[$i] % 2 === 0) { |
||
| 34 | $res[$start++] = $arr[$i]; |
||
| 35 | } else { |
||
| 36 | $res[$end--] = $arr[$i]; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | return $res; |
||
| 41 | } |
||
| 43 |