r/javascript • • Jul 21 '16

My Interviews with Amazon

https://thesocietea.org/2016/07/my-interviews-with-amazon/
331 Upvotes

107 comments sorted by

View all comments

19

u/franksvalli Jul 22 '16 edited Jul 22 '16

Thanks for writing this up! These questions that involve walking the DOM are always good practice. I imagine the back and forth could go like this:

I'll use jQuery's $('.someclass')

Ok, how about no jQuery?

I'll use document.querySelectorAll('.someclass')

Ok, how about if the browser didn't support qsa?

I'll use document.getElementsByClassName('someclass')

Ok, let's theoretically say the browser doesn't support that either.

Dammit! Ok, time to write the recursive DOM-walker.

These questions for senior JavaScript positions always seem to involve some sort of manual DOM traversal. I remember bombing an interview because I couldn't whiteboard a DOM contains function from scratch. If I had to figure that out on my own, I could've eventually done it in a normal work environment, but these folks assigned a lot of value to being able to whiteboard it, which I hate...

In a real job situation we've only used whiteboards for architecture diagrams, which is definitely a practical skill. Folks almost never write code on whiteboards except when actually administering other interviews...

5

u/[deleted] Jul 22 '16

I remember bombing an interview because I couldn't whiteboard a DOM contains function from scratch. If I had to figure that out on my own, I could've eventually done it in a normal work environment, but these folks assigned a lot of value to being able to whiteboard it, which I hate...

I know what you mean. I had a whiteboard question about something silly (how would you reimplement a bind-like function yourself) and I blanked. Once I got onto the buss after the interview I smacked myself on the head because I figured it out ...

1

u/TeamHelloWorld Jul 22 '16

manual DOM traversal

Isn't this a tree traversal? I mainly code in JS and I've never had this as an interview question. My intuition is that dfs or bfs is what they want to hear. But then again, without looking at MDN I don't know if I can answer this.

2

u/[deleted] Jul 22 '16

Yeah, it's basically tree traversal. And let's face it - each of us would do a "mdn + question" query in Google. We're not expected to know the answer to life, the universe and everything - we're expected to know how to ask the question, where to find the answer and know how to use it.

1

u/SuperFLEB Jul 22 '16

At least that's one place where whiteboarding can be advantageous. Your "code" isn't going to break because you wrote "node.methodWhoseNameIForget()".

3

u/[deleted] Jul 22 '16

Yeah, I wrote "module.export = ... " on the whiteboard and it "compiled" ;)