Impromptu testing a junior's mettle part 4
-
Honestly, I'm impressed that he eventually came up with
usort
.
-
"Well I didn't expect this kind of task. I mean, who would ever store data in this strange format?"
Please tell me he didn't actually say that?My experience of interviews (I'm a junior java developer. Yes I'm TR ) has been make a good attempt. Nobody really expects you (at my level anyway) to actually get it done in 30 minutes. Explain your logic and how you would finish it.
One interview I almost got a job out of (a senior dev up and quitted and they have to reprioritise) was I was pair programming and when it came to debugging he was shocked that I wasn't using print statements but actually using the debugger. He thought it was weirder still that I wrote most of the code in the middle of the debugger.
In fairness you're looking for senior devs though. He should of breezed through that. I might steal that test btw.
-
Mines enterprisey! And by enterprisey I mean "ugly, technically works, inefficient (16.5mb of RAM!), fancy, overly designed and fragile"
And done on a machine from which I cannot exfiltrate code aside from photographs.
5 minutes, most of which was googling for the syntax for a literal array.
-
Refactored for modularity.
-
now with all these posted solutions, it should be a breeze to get through @cartman82s interview!
Filed Under: Where do I have to apply again?
Actual post of interest maybe:
So, half a year ago I applied to a PHP dev job. I was super rusty from not programming PHP in quite a while. I mentioned that and also that I wanted to get some experience but was willing to learn.
I am a student (not even CS) and applied for a junior level position at best.The task they handed me was creating a website from scratch (including design... I think?) that was supposed to:
- accept more or less random date
- validate said data
- save data in database
- said database design was also to be done by me
- was supposed to be extendable
- was supposed to show statistics about what was input
- was to be done in 1 hour (including database work, setting up server, etc.
All in all I failed that test because I got overwhelmed. I accept that. It was a doable assignment now that I look back at it.
What I am trying to say is: This assignment is something even I could have done back then... and that makes me sad!
Filed Under: This story actually had no real point. I just felt like telling it. You are welcome!
-
-
now with all these posted solutions, it should be a breeze to get through @cartman82s interview!
Yes, but you then get a job as a php dev. The crime is its own punishment.
-
Hmmm.... Maybe we could try setting @arantor up for that job!
Filed Under: Unless @Arantor is unable to complete the test!
-
because I'm writing the Split function by hand
There's no need for that when the delimiter is spaces though:
https://ideone.com/jCjtV2EDIT: Hmm, not sure what I did to make that 0.99 turn into a 0.98 - oh well it was only proof of concept anyway.
-
My experience of interviews (I'm a junior java developer. Yes I'm TR ) has been make a good attempt. Nobody really expects you (at my level anyway) to actually get it done in 30 minutes. Explain your logic and how you would finish it.
Given this task, I'd totally expect you to get it done in 30 minutes. Maybe excluding the dev environment setup.
I mean, at least in C# and Java splitting the lines is the hardest part, since I think (don't remember) a split on spaces will leave you with a bunch of empty strings inbetween, and even that takes like... two lines, maybe?
-
a split on spaces will leave you with a bunch of empty strings inbetween
You'll be glad to hear that PHP got you covered there:
Filed Under: okay, okay, enough trolling
-
preg_split — Zerlegt eine Zeichenkette anhand eines regulären Ausdrucks
Does this function split a string or invade Poland?
-
If I ever get a hint that is being done to me, I'd solve the problem using 68K Assembly.
I had to use 68K assembly in college. Fortunately, that was a long time ago, so I've managed to repress most of the memories.
-
Does this function split a string or invade Poland?
It's PHP... so you can't be sure either way...
Filed Under: Let me change the link then... jeez...
-
In C#, split has an optional argument that removes empty elements.
-
at least in C# and Java splitting the lines is the hardest part, since I think (don't remember) a split on spaces will leave you with a bunch of empty strings inbetween
In C#, you can specify that you don't want them (see @Weng's screen-photo above), but I think Java will give you a bunch of empty strings.
-
(head -n1; awk '$3 >= 50' | sort -rnk2) <products.txt
-
Google.rs is a really fun domain name.
... Hell, .rs in general is an awesome tld.I wonder if I can register those from here.
... why? I don't see what hipstery clever domain name you can make with "rs".
So what does the data to be parsed look like anyway?
It's literally what I posted above.
Please tell me he didn't actually say that?
Pretty much exactly that.
"I usually just get data from Excel or MySQL, blah blah blah".
Mines enterprisey! And by enterprisey I mean "ugly, technically works, inefficient (16.5mb of RAM!), fancy, overly designed and fragile"
And done on a machine from which I cannot exfiltrate code aside from photographs.
What the hell is that? Where are all the JAVA beans and XML configuration files? I'm disappoint.
now with all these posted solutions, it should be a breeze to get through @cartman82s interview!
The next candidate: "Hmm, what is this strange feeling? My mettle.... it is being tested! Quick, let me google that!"
The task they handed me was creating a website from scratch (including design... I think?) that was supposed to:- accept more or less random date- validate said data- save data in database- said database design was also to be done by me- was supposed to be extendable- was supposed to show statistics about what was input- was to be done in 1 hour (including database work, setting up server, etc.
All in all I failed that test because I got overwhelmed. I accept that. It was a doable assignment now that I look back at it.
That test sounds wholly unreasonable. I'd probably be hard pressed to do it under such circumstances.
What I am trying to say is: This assignment is something even I could have done back then... and that makes me sad!
Note that the fact you're spending your time here instead on Facebook or reading tabloids puts you in the at least above average coder category.
Yes, but you then get a job as a php dev. The crime is its own punishment.
Also, third world level salary.
-
I like the way you handle the first row. Very nice.
-
What the hell is that? Where are all the JAVA beans and XML configuration files? I'm disappoint.
It needs a few hours of refactoring to go full overboard. This would end up as 3 web services. One WebAPI, one SOAP and one WCF over TCP.
-
... why? I don't see what hipstery clever domain name you can make with "rs".
eate.rs, painte.rs, whatever. It's basically begging for a social media website targetted to a specific group.
It's literally what I posted above.
What you probably should be doing is preparing a second file following the same spec, but with different data, and tell the candidate their code has to work on that too without showing them the file... but then again, you want to employ someone.
I usually just get data from Excel
That's, like... an awful lot harder than just parsing the ?SV, isn't it? At least the way we do it is, I guess OLEDB magic might be a bit easier, but still not easier than parsing a (simple, no escaping involved) file.
-
eate.rs, painte.rs, whatever. It's basically begging for a social media website targetted to a specific group.
cartman82:
I was thinking of kissmy.rs (still available!) but when I saw the price I realized why it's still available.
Don't know why it included the beginning of that next quote; I didn't have it highlighted. I even tried it twice to make sure
-
You'll like the edited version even better.
-
That's, like... an awful lot harder than just parsing the ?SV, isn't it? At least the way we do it is, I guess OLEDB magic might be a bit easier, but still not easier than parsing a (simple, no escaping involved) file.
I guess someone already configured all that, and he was just copy-pasting and tweaking. I don't know.
Filed under: 500 storm?
-
Java's split also uses RegExs, which means you can split on
\s+
(which is greedy).
-
I'll post my version when I'm back home and not in front of just an iPad.
But my initial drink-enhances possibly version is split on new line to make an array of lines, unset the first, iterate the rest, preg_split on \s+, intval the last column, remove rows that don't fit the criteria, cast the price to float, uasort that shit and output.
-
... why? I don't see what hipstery clever domain name you can make with "rs".
hipste.rs?
-
-
tdemsy.rs
-
That's, like... an awful lot harder than just parsing the ?SV, isn't it?
No? VBA script call to open the file, find the end of the data, apply auto-filter and filter/sort appropriately...
I actually have a helper module I wrote up that could accomplish all of this in about four lines!
-
In C#, split has an optional argument that removes empty elements.
And now, my Split also does! http://cpp.sh/84rq5 Although the default is to ignore them. I can now handle the actual test data without modification.
-
Wait, so this task is just:
var lines = File .ReadAllLines("Whatever.csv") .Skip(1) .Select(line => line.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries)) .Where(data => int.Parse(data[2]) >= 50) .OrderBy(data => data[1]); foreach(var line in lines) Console.WriteLine("Name: {0} Price: {1} Quantity: {2}", line[0], line[1], line[2]);
right?
Or even:
var lines = File .ReadAllLines("Whatever.csv") .Skip(1) .Select(line => line.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries)) .Where(data => int.Parse(data[2]) >= 50) .OrderBy(data => data[1]) .Aggregate(string.Empty, (all, line) => all + string.Format("Name: {0} Price: {1} Quantity: {2}" + Environment.NewLine, line[0], line[1], line[2])); Console.WriteLine(lines);
-
You seem to forget to strip the header.
Edit :if the parse doesn't take of that.
-
I was never given the spec. All I've seen is some other bits of code here that I tried not to read much of. The OP assumes we know the spec.
-
Edit :if the parse doesn't take of that.
That will probably crash me. I haven't seen the file.
-
Anyway, if a header needs to be removed...
var lines =
File
.ReadAllLines("Whatever.csv")
.Skip(1)
.Select(line => line.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries))
-
Why is this in IHOC anyway? Is @cartman82 secretly an Oracle recuiter?
-
Why is this in IHOC anyway?
Categorical mis-selection? OP mentioned they tried to select two categories at once (or something)
Filed under: No two of these can be in the same category.
Also, because Continuing the discussion from About the The I-Hate-Oracle Club category:
I-Hate-Oracle-Club: Because it's time we senselessly bash someone besides Microsoft.
-
-
@swayde said:
Edit :if the parse doesn't take of that.
That will probably crash me. I haven't seen the file.
It was here:
```text
PRODUCT PRICE QUANTITY
Apple 0.75 125
Orange 0.80 218
Pear 0.99 116
Pineapple 1.75 45
Watermelon 1.15 20Will `int.Parse` blow up when it tries to eat `"QUANTITY"`? Or return `0` or `NaN`, neither of which should be `>= 50`, so it'll just ignore that line.
-
My later update skipped the header. Without, it will indeed break. I don't use an insane language where NaN is a valid int.
-
Maybe this well known web site runs on WordPress and he does everything with plugins. There are a while lot of WordPress "developers" who can't write PHP or JavaScript, and barely know HTML and CSS.
THIS! SO MUCH THIS!
-
Here's a version in PHP.
<?php // Get the file, split it into an array, drop the header $file = file(__DIR__ . '/file.txt'); $headers = preg_split('/\s+/', trim($file[0])); unset($file[0]); // Iterate over the content, split it up and get things // into the right types for later. array_walk($file, function (&$line) { $line = preg_split('/\s+/', trim($line)); $line[1] = (float) $line[1]; $line[2] = (int) $line[2]; }); // Strip out cases of the quantity being less than 50 $file = array_filter($file, function($line) { return $line[2] >= 50; }); // Sort by price descending uasort($file, function($a, $b) { return $a[1] > $b[1] ? -1 : ($a[1] == $b[1] ? 0 : 1); }); // Output echo ' <table> <tr>'; foreach ($headers as $header) { echo ' <th>', $header, '</th>'; } echo ' </tr>'; foreach ($file as $line) { echo ' <tr> <td>', implode('</td><td>', $line), '</td> </tr>'; } echo ' </table>';
I could possibly have done it less retardedly without using the array walker or filtering, and by simple iteration, but this seemed cromulent enough and pretty-printed.
And in 12 minutes while watching a film.
-
Here's Javascript.
var csv = "PRODUCT PRICE QUANTITY\n" + "Apple 0.75 125\n" + "Orange 0.80 218\n" + "Pear 0.99 116\n" + "Pineapple 1.75 45\n" + "Watermelon 1.15 20"; function parse(csv) { return csv.match(/.+/g).map(l=>l.match(/\S+/g)) .filter(l=>+l[2]>=50).sort((a,b)=>b[1]-a[1]); } alert(parse(csv).join("\n"));
Oh, you wanted an array of objects? Sure...
function parse(csv) { return csv.match(/.+/g).map(l=>l.match(/\S+/g)) .map((l,i,a)=>l.reduce((o,e,i)=>(o[a[0][i]]=e,o),{})).slice(1) .filter(l=>+l.QUANTITY>=50).sort((a,b)=>b.PRICE-a.PRICE); }
-
Pfft. It's a 1-liner in LINQ.
-
I think so far the bash solution won the golf contest.
-
Probably, I wasn't attempting to play golf with mine.
-
Yeah persactly. I guess it's slightly more complicated than I thought, but not much.
-
-
I Hate Oracle Club