4 ms·
A decently clever candidate could sneak out of that first one without a loop. Something like numbers.reduce((a,b) => Math.min(a,b)) would do it in JavaScr
by rpeden 9y ago
A decently clever candidate could sneak out of that first one without a loop. Something like
numbers.reduce((a,b) => Math.min(a,b))
would do it in JavaScript. In general, if a candidate realizes they can use reduce for that purpose, in my experience interviewing candidates they probably wouldn't have much trouble doing it with a loop, and it would usually be a signal they're going to have a pretty good interview.
Then again, you might run into a joker who has just memorized how to use reduce for finding the maximum or minimum element in a list of numbers.
- WorldMaker 9y agoI find that's a telling way to determine the experience of the interviewer. I'm saddened by the number of times an interviewer has asked me, "What is a reduce? How does it work?" Of course, that information isn't very helpful in the flow of an interview, it's mostly just upsetting.
- deathanatos 9y agoAs of yet, nobody has used reduce(). If they did, and especially if they followed it with a coherent explanation of what reduce does & how it worked (and convinced me they've not memorized reduce for a singular purpose, but understand it well enough to apply it generally), I'd definitely accept it. If they can also write, or at least quickly approximate, the for-loop solution too, then I'd say I've gotten an excellent signal: not only can the candidate write a for loop, but he or she might also have some experience with a functional paradigm from somewhere.