Today’s Interview Question: String Reversal
Meg Adams

The frustration is eminently understandable; there’s nothing more annoying than interview questions which essentially come down to “have you heard this riddle before” or “did you prepare for this obvious trap.” And your complaint that the question is essentially about something that no one does ever is very well-taken. It’s definitely not clear what the value of such a question is.

That said, I think I’d actually defend this question (though not necessarily the other ones you reference) for a couple of reasons.

The first is that there’s a lot to be said for finding out how a programmer does when they get out of their comfort zone. Just about anyone can learn to do the same sort of problem over and over; but if a new technology or something comes along the nature of that problem might change quickly — or it might be that in addition to the standard problems, new and strange ones might come up in the course of projects. There’s also a lot of benefit to someone that approaches old problems in novel ways — which is less likely if they’re not great at what they aren’t used to. That said it’s probably not a reason to use this question as a disqualifier against someone who flubs it, if the job in question involves solving similar problems all the time.

The second is about style. The indexing error you mentioned is really easy to make, as are other errors like it. Getting a number wrong in the wrong place can easily lead to productivity-devouring bug hunts. But you never actually need to expose yourself to an indexing error. You could use a for-of statement:

var reversed_string = '';
for (let letter of string_to_reverse) {
reversed_string = letter + reversed_string;
return reversed_string;

Whether or not a programmer uses this (or something like it) is really revealing. First of all, it says they know about it — not a trivial thing, given the relative recency of its introduction into javascript. Second, it says they understand its value — that by removing the index entirely from the code, it reduces the chances of programmer error, and also makes the code a lot easier to read. Both of those things — error probability and readability — are very high-value, because increasing them generally reduces the amount of time developers have to spend with the code to get it working, or in the case of the readability, to revise it, which is a big deal, because developers are expensive. But readability and error-proneness are also things that a huge cohort of programmers entirely ignore, whereas they will concentrate to no end on the dumb macho exercise to make their code go faster, which is usually pointless; in javascript, for example, the binding constraint is almost always database calls. Knowing that a programmer is paying attention to readability and error-proneness — especially in an “easy case” like this one, because “easy cases” are often more likely to produce errors than cases you’ve concentrated on because they’re tricky— is valuable.

Still, you have my sympathy. It’s still no fun to feel like you’ve been gotcha’d, since in many cases, the interviewer might not even be cognizant of the points I made above. They might just be asking it because someone asked them — a dumb reason if there ever was one.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.