Created
May 27, 2017 13:56
-
-
Save Cvetomird91/64466b978abb9b58b319fa81ed8fb325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//solution for Test Dome PHP File Owner Task | |
class FileOwners | |
{ | |
public static function groupByOwners($files) | |
{ | |
$owners = array_unique($files); | |
$sorted = array(); | |
foreach ($owners as $owner) { | |
$sorted[$owner] = array(); | |
} | |
foreach ($files as $file => $owner) { | |
array_push($sorted[$owner], $file); | |
} | |
return $sorted; | |
} | |
} | |
$files = array | |
( | |
"Input.txt" => "Randy", | |
"Code.py" => "Stan", | |
"Output.txt" => "Randy", | |
); | |
print_r(FileOwners::groupByOwners($files)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment