This interview could go much faster if it didn't use a laptop or a whiteboard. A strong candidate should fire off responses to those questions just as fast as you can ask them.
Spacify: "Split on empty, join with spaces." Done.
String.spacify: "Attach that function to String.prototype and call the split/join on `this`." Done.
And so on. It does serve as a way to test if they can actually write code, but my guess is that there's not that big a difference between talking through the code you'd write and actually writing it.
I'd be very comfortable with going through this verbally, but I'd be horrified to get an interview like this where they expect me to type code and talk to them while doing it. I'd honestly much rather have a whiteboard than a laptop—at least I'm used to writing with a pen while someone judges me. The laptop would just take away that comfort and make sure my brain turns off.
The split on empty thing seems silly to me. It's a hack. If you weren't familiar with the specific javascript implementation, you might expect split to return ['hello world']. It's a nice hack, but it's a hack. It's something you can do if you offhand know about that quirk of split.
I would think an advantage to using split/join is that you aren't concatenating a lot of immutable strings together (although if this only happens one time and for a short string, it may not matter.)
Edit: Not tested myself. I had a suspicion about it and "confirmed" it via an older post that is perhaps outdated now. Updated this comment to sound less authoritative ("I would think").
One thing I've learned from jsPerf is that this sort of micro-tuning tends to be particularly fruitless in JavaScript. Even if a tweak increases speed consistently across the target browsers, there's no telling which will optimize what cases in the next few versions.
Basic things like caching DOM lookups are always good, but not so much the little things.
The join() hack used to be significantly faster for many/long strings a couple years ago, but I wouldn't be surprised if things have changed since then. I'd be interested to see your results.
I think it's better to use the laptop because that is the "language" I should be mostly comfortable with to be a good candidate, unfortunately I am not half as good with expressing what I would do. I would be also pretty nervous which obviously won't help. Instead typing could make feel more secure.
No. Not at all. You could even have a conversation broaching some of these topics in a more casual way and tell if the candidate knows what he's talking about in a lot of cases. Heck, even answers about function arguments could be answered satisfactorily enough if the candidate knew about the "arguments" object.
Spacify: "Split on empty, join with spaces." Done.
String.spacify: "Attach that function to String.prototype and call the split/join on `this`." Done.
And so on. It does serve as a way to test if they can actually write code, but my guess is that there's not that big a difference between talking through the code you'd write and actually writing it.
I'd be very comfortable with going through this verbally, but I'd be horrified to get an interview like this where they expect me to type code and talk to them while doing it. I'd honestly much rather have a whiteboard than a laptop—at least I'm used to writing with a pen while someone judges me. The laptop would just take away that comfort and make sure my brain turns off.
Am I alone in that?