Code through the looking glassAnd a linear search to rule them
The final piece for this candidate is the code to actually search through the sorted array. As you'll recall, the candidate certainly made our computer pay for that sorting and merging. But we are fine now, we have manage to recover from all of that abuse, and we are ready to rock.
Here is how the search (over sorted array) was implemented.
public List<int> EmailSearcher(string email) { List<int> answer = new List<int>(); for (int i = 0; i < emailsArray.Length; i++) { if (emailsArray[i].STR.ToString().Equals(email, StringComparison.OrdinalIgnoreCase)) { answer = emailsArray[i].ID; return answer; } } return answer; }
And with that, I have nothing left to say.
More posts in "Code through the looking glass" series:
- (18 Mar 2016) And a linear search to rule them
- (17 Mar 2016) Sorting large data sets
- (16 Mar 2016) I'm the God of all OOP
- (15 Mar 2016) All you need is a dictionary (and O(N) )
- (14 Mar 2016) Finding today's log file
Comments
@Ayende, where do you find this candidates? this seems like a good joke, and actually its funny and made me laugh. sorted arrays / binary search is one of the first lessons in computer science. seriously, are this cases real? i have nothing left to say :)
I have no doubt this is real code from a real developer and not intended to be a joke. I have found so much insane stuff in shipping code over the past 20+ years that I question the developer's sanity.
My favorite is that they needed data sorted at "multiple levels". Instead of doing something obvious, they created a WinForms TreeView, added all the data and turned on sorting of the items. The TreeView was never shown, it was just a handy data structure. Ignoring the insanity, it was a pretty interesting solution.
I guess that's what happens when you combine downvoted answers from StackOverflow...
List<int> answer = new List<int>();
That shows that he does not have a basic understanding of variable initialization. He also does not know common control flow patterns, either.
Uri, This particular candidate came from a recruitment agency. Actually, from our main recruitment agency. They have been the source for over 50% of our team, and are responsible for two new hires in the latest round.
David, I love that!
Mark, Actually, that one I don't mind. It might be just an issue of how they got used to structuring the code, to avoid returning null.
Does this person has any experience? It's kinda sad if he does.
Ok, yeah I took for granted that this guy would be doing a binary search with this approach. Don't hire him.
Comment preview