To view parent comment, click here.
To read all comments associated with this story, please click here.
Now you are showing ridiculous behaviour.
You show to your working comrades a young boys code for teh lulz (which is a form of sadism), and then don't even now that abs() is a standard function?
Fellows and Me: "What."
Seriously: If you want a simple and elegant solution:
#include <algorithm>
...
std::abs(...)
...
Edited 2012-09-25 12:09 UTC
Phreck, again, the question is essentially "do you have an idea how abs()" is implemented? If you answered "just use abs()," you're screwed.
The point of the question is to test basic programming knowledge and skill (i.e. to answer the question: "can this young man think like a programmer?")
If you don't like that kind of question, you can either avoid programming job interviews, or don't ask them to interviewees.
Edit: when I was in the interviewee's position (a long time ago) I was even asked to write a FizzBuzz code. Now that's ridiculous.
Edited 2012-09-25 12:49 UTC





Member since:
2010-06-12
Yes, sure... There's abs(). There are a gazillion other functions offered by various 3rd-party libraries for various purposes. Heck, one could even Google for solutions to basic programming problems. But a) we cannot always depend on 3rd-party solutions in real projects (most of the times we have to implement our own libraries or at least fork something that's closest to our requirements), and b) we need a programmer who can come up with good solutions without depending on Google Search.
If one doesn't remember such a basic thing he/she learned at school, what else has he/she forgotten?