Front End Developer – Interview Questions
101–110 of 152 posts
Re: Front End Developer – Interview Questions
#102Earlier 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
#103Earlier 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
Re: Front End Developer – Interview Questions
#104Earlier 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.
Re: Front End Developer – Interview Questions
#105Earlier 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.
Re: Front End Developer – Interview Questions
#106Earlier 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.
Re: Front End Developer – Interview Questions
#107Re: Front End Developer – Interview Questions
#108Earlier 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?
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
#109I think you meant: "i'm a lasagna hog"
Re: Front End Developer – Interview Questions
#110Earlier 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.
function foo(s) {
a = Array(s);
for (var i = 0; i