Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.

Am I alone in that?



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.


Alternatively: "Iterating through the string, take each character and dump it plus a space to a temp string. Return the temp string trimmed."

I wouldn't say that's any worse, especially in this scenario. But they should get it just as quickly.

Edit: trim the string. :)


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").


Someone already set up a jsperf test for this an hour or so ago, so I added my regex solution. http://jsperf.com/spacify/2

On my machine, I was surprised to see that the for loop is the fastest (Chrome + Crunchbang).

I'd guess that this is probably because looping structures are heavily optimized in modern JS engines.


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.


Yup, I just ran the tests again and the results are completely different and what difference there is is basically negligible.


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.

Edit: Apparently the loop is faster.[0] :)

[0] https://news.ycombinator.com/item?id=7149833


The loop doesn't even do the same thing since it adds an extra space at the end.

Fixed: http://jsperf.com/spacify/4


It's pretty common I'd say. Modifying the String prototype, however..


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: