2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNW\Skills;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Helper class to sort ranks in non-decreasing order.
|
|
|
|
*/
|
2010-08-28 22:05:41 -04:00
|
|
|
class RankSorter
|
|
|
|
{
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Performs an in-place sort of the items in according to the ranks in non-decreasing order.
|
2016-05-24 14:10:39 +02:00
|
|
|
*
|
2023-08-02 14:14:10 +00:00
|
|
|
* @param array<mixed> $teams The items to sort according to the order specified by ranks.
|
|
|
|
* @param array<int> $teamRanks The ranks for each item where 1 is first place.
|
|
|
|
* @return array<array>
|
2010-10-08 21:44:36 -04:00
|
|
|
*/
|
2023-08-02 13:19:35 +00:00
|
|
|
public static function sort(array &$teams, array &$teamRanks): array
|
2022-07-05 15:33:34 +02:00
|
|
|
{
|
2010-08-28 22:05:41 -04:00
|
|
|
array_multisort($teamRanks, $teams);
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2010-08-28 22:05:41 -04:00
|
|
|
return $teams;
|
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|