Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Created May 27, 2017 13:56
Show Gist options
  • Save Cvetomird91/64466b978abb9b58b319fa81ed8fb325 to your computer and use it in GitHub Desktop.
Save Cvetomird91/64466b978abb9b58b319fa81ed8fb325 to your computer and use it in GitHub Desktop.
<?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