Live data from Hacker News

Front End Developer – Interview Questions

github.com

101–110 of 152 posts

Re: Front End Developer – Interview Questions

#102
post #74
post #62

Earlier quoted context omitted.

The only solution I could think of is this: function foo(n) { var result = []; for (var i = 0; i What are the two others?

You could use Function.prototype.bind in a couple ways, or even Array.prototype.map (though sadly you can't really do new Array(n).map, if that was true you could make this a one-liner). // new Array(n) could just be [] in all examples // // using Array.prototype.map // sadly you can't do new Array(n).map // because it doesn't iterate over undefined functions function foo(n) { for (var ret = new Array(n), i = 0; i

  function foo(a){
    return Array.apply(0, new Array(a)).map(function(_, b){
      return Number.bind(null, b)
    });
  }

Re: Front End Developer – Interview Questions

#103
post #50
post #32

Earlier quoted context omitted.

I feel bad, because as I was writing a solution to this I knew why it wouldn't work and why (returning my counter variable returns the value at the end of the count) but I still couldn't come up with a fix :( Edit: A good Google seems to suggest using JSON.stringify and JSON.parse to copy the value. Edit 2: But even that doesn't seem to work :( Edit 3: Got it, using a generator function. Which makes sense. I guess I'…

Using a closure: function foo(s) { function generator(i) { return function () { return i; }; } var r = new Array(s); for (var i = 0; i Using Function.prototype.bind(): function foo(s) { function generator(i) { return i; } var r = new Array(s); for (var i = 0; i

[deleted]

Re: Front End Developer – Interview Questions

#104
post #17

Earlier quoted context omitted.

Call and apply are core concepts to writing good javascript. I would not hire someone (at least for any sort of senior role) that could not tell you exactly how both of them work. Many of the other things on this page are certainly "trivia" that could be addressed by google when they come up, but not those.

How often do you use call and apply? I've been a JS developer for a long time, have written a lot of JS code, and rarely need to use call and apply. Unless you're writing all your code from scratch and not using any frameworks / util libs (which you should) you won't need them very often.

Agreed I can't even recall the last time I used call or apply. We might have only a handful of cases out of roughly 200,000 JS lines of code.

Re: Front End Developer – Interview Questions

#105
post #42

Earlier quoted context omitted.

It's a good question, and a pretty fair one for a Javascript developer to know, given the role that closures play in the language. That said, I'm not thinking of a 3rd solution. Closures(best?), a global(worse), what else? Edit: As Daiz points out, the bind I was thinking of doesn't even have to even be to a global. But we still have seen only two solutions: variations of binding and closures. What's the third? Inqui…

The 3 solutions that I came up with are: - bind - function creator outside of the loop called from within - create an anon function on each loop iteration that acts like the function creator in #2 The bind is best in terms of memory and simplicity, but will not run on on IE 8 or crappier, so in that case #2 is preferred. The last one creates anon functions needlessly, but is very compact to write.

fourth solution would be naming the function with the iterator (as in my example below) and calling indexOf(iterator) when the function is invoked

Re: Front End Developer – Interview Questions

#106
post #95
post #88

Earlier quoted context omitted.

Fairly often. Since the selected DOM element is the value of this in any event handler callback, you can migrate out the function and use it for different things (i.e. validation of, say, autofill after a settimeout) and different contexts with call/apply.

I don't see how this requires you to know the intricacies of call/apply or how it would even force you to use it frequently enough to understand the difference.

I guess I don't understand. There's a lot of ways to accomplish tasks in any programming language but in JS in particular there's a way to assign the value of this and you can use it to have clean, dry code, and I'd expect any sr. level people to know how to use it. jQuery source has over 100 uses of call and apply.

Re: Front End Developer – Interview Questions

#108

Earlier quoted context omitted.

A startup I worked for made the applicants do pair programming for two days. Needless to say, the people getting hired were very good. Of course, if you are in a big company this is too much time and work (Recently had 6 interviews at big corps, not a single line of code written for a junior position)

"A startup I worked for made the applicants do pair programming for two days. Needless to say, the people getting hired were very good." How is this even possible for people that already have a job? Are they supposed to take two days vacation or do it in the weekend?

Good question.

I really don't know because I was only an intern, but I guess they took vacation days (law mandates minimum 20/year). But I also recall a discussion here on HN on this topic, where applicants (at a different company) were in invited to work on a weekend.

2 days is probably overkill for US-companies, but a bit of pair-programming on real problems seems a lot better than "Let's see if you memorized this trivia fact you'll never need in your job"

Re: Front End Developer – Interview Questions

#110
post #42

Earlier quoted context omitted.

It's a good question, and a pretty fair one for a Javascript developer to know, given the role that closures play in the language. That said, I'm not thinking of a 3rd solution. Closures(best?), a global(worse), what else? Edit: As Daiz points out, the bind I was thinking of doesn't even have to even be to a global. But we still have seen only two solutions: variations of binding and closures. What's the third? Inqui…

The 3 solutions that I came up with are: - bind - function creator outside of the loop called from within - create an anon function on each loop iteration that acts like the function creator in #2 The bind is best in terms of memory and simplicity, but will not run on on IE 8 or crappier, so in that case #2 is preferred. The last one creates anon functions needlessly, but is very compact to write.

5 solution with eval

  function foo(s) {
    a = Array(s);
    for (var i = 0; i 
Post reply on HN