Hi, I am looking to hire a programmer. The applicant must possess tangible experience with php programming. To help us evaluate your capacities, you will go through a series of 3 tests. For the first one, you must write a program that can sort all the lines of the attached file in alphabetical order, case insensitive, and removing the duplicates. File is attached. Please PM me the code as I do not want other applicants to copy your code.
Putting coders through tests is ridiculous, why not ask for a portfolio? Or a guarantee of sorts, not stupid tests, anyone could code that, but the difference is in the way that its coded.
I'm aware this may be a con to get free work but since the 'test' is simple enough I'll go along with it <?php $data = file_get_contents("data.txt"); $array = explode("\n", $data); $array = array_unique($array); sort($array); $newdata = ""; foreach($array as $item){ $newdata .= "$item\n"; } file_put_contents("data.txt", $newdata); ?> PHP: ...and the final output: Ochre Office green Old Gold Old Lace Old Lavender Old Rose Olive Olive Drab Olivine Orange (RYB) Orange (color wheel) Orange (web) Orange Peel Orange-Red Orchid Pale blue Pale brown Pale carmine Pale chestnut Pale cornflower blue Pale magenta Pale pink Pale red-violet Pale taupe Papaya whip Pastel green Pastel pink Payne's grey Peach Peach-orange Peach-yellow Pear Periwinkle Persian blue Persian green Persian indigo Persian orange Persian pink Persian red Persian rose Persimmon Pine Green Pink Pink-orange Platinum Plum (web) Portland Orange Powder blue (web) Prussian blue Psychedelic purple Puce Pumpkin Purple (HTML/CSS) Purple (X11) Purple Taupe Raspberry Raw umber Razzmatazz Red Red (RYB) Red (pigment) Red-violet Rich carmine Robin egg blue Rose Rose Madder Rose Taupe Rose pink Rose quartz Royal blue Royal purple Ruby Russet Rust Safety orange (blaze orange) Saffron Salmon Salmon pink Sandy brown Sangria Sapphire Scarlet School bus yellow Sea Green Seal brown Seashell Selective yellow Sepia Shamrock green Shocking Pink Sienna Silver Sky Blue Slate gray Smalt (Dark powder blue) Spring bud Spring green Steel blue Code (markup):
I've already had people with good looking portfolios that couldn't even do a few simple tasks (like the one I posted here). I've had portfolios which were montage of examples from php.net. A test also indicates if someone pays attention to details and can follow instructions. They also show how they think.
No one has yet to give a 100% correct answer as the requirement of it being case insensitive is missing from the answers that have been submitted.
<?php $file = file_get_contents("sample_data.txt"); $arr = explode('\n',$file); natcasesort($arr); print_r($arr); ?>
I think I have some real brains in my team, but I'll put their time with you test only when I see it is worthwhile. So, please let me know a bit about your project you'll give after passing test. What price? Looking for long term coder or not? Hope you understand. Thanks in advance.
Only one person got the complete answer. The best solution, however, is: <?php $array = file("sample_data.txt"); $array = array_unique($array); natcasesort($array); print_r($array); ?> Code (markup):
Well, you didn't specify natural sort order, only alphabetic that's why I only sent you array_multisort not natcasesort. I considered using natcasesort, but it was more than specified, and you explicitly asked for attention to detail