Created
May 24, 2017 01:09
-
-
Save ltfschoen/5bf399c6a9cc320641aea4f5401cb267 to your computer and use it in GitHub Desktop.
sort
This file contains hidden or 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
| Write a routine that presents a random list of candidates in preferred order based on skills, communication and experience | |
| with experience being half as important than the other two attributes. | |
| * Do not use the built-in sort function | |
| * Use the task1.php template provided | |
| * You will be judged on coding style and also the algorithm that you use | |
| #!/usr/bin/php | |
| <?php | |
| function RandomName($length) | |
| { | |
| $letters = "abcdefghijklmnopqrstuvwxyz"; | |
| $name = ''; | |
| for ($i=0; $i<$length; $i++) { | |
| $name .= substr($letters, mt_rand(0,25), 1); | |
| } | |
| return $name; | |
| } | |
| function GenerateRandomCandidates() | |
| { | |
| $names= array("John", "Jill", "Julie", "Jane", "Jeff", "Joe", "Jimmy"); | |
| $ua = array(); | |
| for ($i=0; $i<7; $i++) { | |
| $ua[] = array( | |
| "name" => $names[mt_rand(0,5)] . ' ' . ucfirst(RandomName(3)), | |
| "age" => mt_rand(18,65), | |
| "communicaton_rating" => mt_rand(1,10), | |
| "skills_rating" => mt_rand(1,10), | |
| "experience" => mt_rand(1,10) | |
| ); | |
| } | |
| return $ua; | |
| } | |
| function showCandidates($list) | |
| { | |
| for ($i=0; $i<count($list); $i++) { | |
| $person = $list[$i]; | |
| echo $person['name'] . ': age:' . $person['age'] . | |
| ', communicatons:' . $person['communicaton_rating'] . | |
| ', skills:' . $person['skills_rating'] . | |
| ', experience: ' . $person['experience'] . "\n"; | |
| } | |
| } | |
| // implement this function and any other required functions | |
| function sortCandidates($randomlist) | |
| { | |
| return $randomlist; | |
| } | |
| $allCandidates = GenerateRandomCandidates(); | |
| echo "# Random List\n"; | |
| showCandidates( $allCandidates ); | |
| $result = sortCandidates($allCandidates); | |
| echo "\n# Prefered List\n"; | |
| showCandidates( $result ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment