From: Dmitry A. Soshnikov on
On 08.05.2010 9:20, Garrett Smith wrote:
> Dmitry A. Soshnikov wrote:

[...]

>
>>
>> "What does result alert(this)?"
>>
>> without mentioning the context of the question -- let the candidate
>> will explain all this himself.
>>
>
> Testing unspecified host method string conversion seems unreasonable;
> nothing can be guaranteed to be expected.
>

If would be a good answer though, if you answered so. Then I can check
that you before the talking about this `this` value, clarify some other
deep question.

But at the same time, I mention that you didn't get the _main_ point of
the question, but started to talk first about some irrelevant thing.
I.e. it could seem that you didn't understand the question about exactly
`this`, but talking about some `alert` about which an employer isn't
asking. So, be careful, your (even fair and good attempts to show that
you _additionally_ knows also something other) can be treated in
different way that you thought.

Nevertheless, in general -- yes, as a short addition it will be good to
mention _clarifying_ stuff.

And I was interested of course about whether an employee knows `this`
value topic. And term "context" meant not even execution contexts, but
"all possible situations related with `this` value".

I've heard even answers such as: "Hum... what.. ? [object Window]..".
Such employee nevertheless can be also a good practical programmer.

Another talk, if an employee starts his speech from the e.g. "`this`
value determines on entering the context and depends on...". That's it
-- this is another relative knowledge level.

>> Or, more practical:
>>
>> "Let there is an array. How to remove all elements with value 3 from
>> it?"
>>
>> this question allows to check whether the candidate knows that
>> "length" is being modified every time when he will be splicing/
>> deleting items, and therefore direct for-loop isn't fit.
>>
> Sure, splice modifies length. Is that not what you want?
>

Yes, exactly this I meant. Such small practical examples can help to
test also some theoretically-piratical aspects.

> What result is wanted?
>
> var a = [3,1,2,3,4,3,4,5,3];
> removeThrees(a);
> a
> => ?

No matter what will you use, the issue is to remove all 3. It can be:

[1,2,4,4,5] or

[,1,2,,4,,4,5,]

Dmitry.
From: Mel Smith on
>>What's the difference between a Duck ?
>
> See: http://www.swiftys.org.uk/wiz?1461

Sorry, the answer is:

"One of its legs is both the same."

(and note the correct usage of "its" )

You guys 'quack me up' !

but enough already :(

-Mel


From: John G Harris on
On Fri, 7 May 2010 at 05:54:52, in comp.lang.javascript, Michael Haufe
("TNO") wrote:
>On May 7, 2:27�am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>> Hi Everybody,
>>
>> What is your most challenging interview question?
>
>
>Q: How would you implement a constructor that inherits a method from
>it's prototype that has access to it's instance private variables?
<snip>

It turns out you're interviewing Douglas Crockford. He gives you a two
hour lecture on how constructors are evil, evil, evil. :-)

John
--
John Harris
From: Garrett Smith on
David Mark wrote:
> Garrett Smith wrote:
>> Dmitry A. Soshnikov wrote:
>>> On May 7, 3:07 pm, Richard Cornford <Rich...(a)litotes.demon.co.uk>
>>> wrote:
>>>> On May 7, 11:45 am, Ry Nohryb wrote:
>>>>
>>>>
>>>>
>>>>> On May 7, 10:17 am, David Mark wrote:
>>>>>> Ry Nohryb wrote:
>>>>>>> On May 7, 9:27 am, Garrett Smith wrote:
>>>> <snip>
>>>>>>>> What is your most challenging interview question?
>>>>>>>> Mine:
>>>>>>>> "What do you think of jQuery?"
>>>>>>> A: It's a library that attempts to provide a better browser API.
>>>>>> Attempted and failed (miserably). Have you looked at their API?
>> Nope.
>>

To clarify, I did not mean "Nope I haven't," I meant it as negative
acknowledgment of that answer in an interview.

>> Technical questions and comments are usually threatening to a jQuery
>> developer who has not looked at the source code.
>
> Even worse, they would seem to be threatening to the developers who
> _write_ the source code. Deep down, they know they are running on
> guesswork and hate to have doubts brought to the surface.
>

That is only relevant when the interviewer is a jQuery core developer.

[...]

>>>
>> Not about jQuery. jQuery is unsuitable for professional development. But
>> you can't say that in an interview, and especially not to someone who
>> likes jQuery.
>
> Which is why I would never attend such an interview.

Most use jQuery these days; so it's pretty hard to both avoid.

[...]

>>> "What does result alert(this)?"
>>>
>>> without mentioning the context of the question -- let the candidate
>>> will explain all this himself.
>>>
>> Testing unspecified host method string conversion seems unreasonable;
>> nothing can be guaranteed to be expected.
>
> I think the point was that, without context, you don't know what - this
> - is.
>


The problem with the question: "What does result alert(this)?"

is that it requires too detailed assumptions to answer correctly.

The alert method accepts a string and displays that in a dialog box to
the user with a button that, when activated, closes it.

What `alert` does when supplied with a value that is not a string value
is not specified. Observations may show that implementations perform a
conversion, however undocumented, to get a string value from that value.
How that string value is obtained is not documented.

The behavior of the alert method is not specified in any standard.
Implementations may vary. If the focus is on string conversion of the
`this` value, then use that, e.g.

var selfString = String(this);
alert(selfString);

- is acceptable.

>>> Or, more practical:
>>>
>>> "Let there is an array. How to remove all elements with value 3 from
>>> it?"
>>>
>>> this question allows to check whether the candidate knows that
>>> "length" is being modified every time when he will be splicing/
>>> deleting items, and therefore direct for-loop isn't fit.
>>>
>> Sure, splice modifies length. Is that not what you want?
>>
>
> As Richard mentioned, it doesn't matter if you loop backwards.

Before the question can be answered, the expected outcome needs to be
stated clearly. I can think of a couple of forward loop solutions, one
using splice, one using concat. A reverse loop solution did not occur to me.

Where supported:

[3,1,2,3,4,3,4,5,3].filter(function(i){
return i !== 3;
})


If, given the aforementioned array with the removeThrees function below:

var a = [3,1,2,3,4,3,4,5,3];
removeThrees(a);

a now has elements: [1, 2, 4, 4, 5].

function removeThrees(array) {
var b = a.slice(),
j = 0,
i = j,
el;
for(; i < b.length; i++) {
el = b[i];
if(el !== 3) {
a[j++] = el;
}
}
a.length = j;
return a;
}

I can't see how using `splice` in a forwards loop would be a problem at
all. I find that approach to be easy to understand and I use it in my
own code.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Dmitry A. Soshnikov on
On 08.05.2010 23:56, Garrett Smith wrote:
> David Mark wrote:
>> Garrett Smith wrote:

[...]

>>>>>>>> A: It's a library that attempts to provide a better browser API.
>>>>>>> Attempted and failed (miserably). Have you looked at their API?
>>> Nope.
>>>
>
> To clarify, I did not mean "Nope I haven't," I meant it as negative
> acknowledgment of that answer in an interview.
>

And why is this a crime to examine any library's (including jQuery)
code? I don't see that this is a negative acknowledgment on an interview.

>
> [...]
>
>>>>
>>> Not about jQuery. jQuery is unsuitable for professional development. But
>>> you can't say that in an interview, and especially not to someone who
>>> likes jQuery.
>>
>> Which is why I would never attend such an interview.
>
> Most use jQuery these days; so it's pretty hard to both avoid.
>
> [...]
>
>>>> "What does result alert(this)?"
>>>>
>>>> without mentioning the context of the question -- let the candidate
>>>> will explain all this himself.
>>>>
>>> Testing unspecified host method string conversion seems unreasonable;
>>> nothing can be guaranteed to be expected.
>>
>> I think the point was that, without context, you don't know what - this
>> - is.
>>
>
>
> The problem with the question: "What does result alert(this)?"
>
> is that it requires too detailed assumptions to answer correctly.
>
> The alert method accepts a string and displays that in a dialog box to
> the user with a button that, when activated, closes it.
>
> What `alert` does when supplied with a value that is not a string value
> is not specified. Observations may show that implementations perform a
> conversion, however undocumented, to get a string value from that value.
> How that string value is obtained is not documented.
>
> The behavior of the alert method is not specified in any standard.
> Implementations may vary. If the focus is on string conversion of the
> `this` value, then use that, e.g.
>
> var selfString = String(this);
> alert(selfString);
>
> - is acceptable.
>

You still talk about irrelevant thing; meanwhile Mark has understood it
correctly. I repeat, it is doubtful what is better -- to mention such
long detailed but irrelevant explanation of "alert" or not. An employer
can listen to this reply, make some marks (e.g. "didn't get the main
goal of the question right away" or "a good clarification addition
before the answering the main goal of the question; possible, he likes
to debate -- and no matter about what" -- it depends on an interviewer
and an employer).

So, I think it is good to make some _small_ clarification (such as: "you
understand that alert's result is can be host-environment specific, so I
think we're just talking about exactly `this` value, right? OK. " And
after that -- detailed explanation about the _major_ goal, but not about
irrelevant "alert" and more -- in detailed non-needed view).

Don't forget that a job interview isn't just a technical knowledge test.
Ideally, you should test and understand as much about an employee as
possible, including his personal qualities, how he finds solutions for
suggested issue, whether he can to see the major problem and to place
priorities accordingly.

>>>> Or, more practical:
>>>>
>>>> "Let there is an array. How to remove all elements with value 3 from
>>>> it?"
>>>>
>>>> this question allows to check whether the candidate knows that
>>>> "length" is being modified every time when he will be splicing/
>>>> deleting items, and therefore direct for-loop isn't fit.
>>>>
>>> Sure, splice modifies length. Is that not what you want?
>>>
>>
>> As Richard mentioned, it doesn't matter if you loop backwards.
>
> Before the question can be answered, the expected outcome needs to be
> stated clearly. I can think of a couple of forward loop solutions, one
> using splice, one using concat. A reverse loop solution did not occur to
> me.
>
> Where supported:
>
> [3,1,2,3,4,3,4,5,3].filter(function(i){
> return i !== 3;
> })
>
>
> If, given the aforementioned array with the removeThrees function below:
>
> var a = [3,1,2,3,4,3,4,5,3];
> removeThrees(a);
>
> a now has elements: [1, 2, 4, 4, 5].
>
> function removeThrees(array) {
> var b = a.slice(),
> j = 0,
> i = j,
> el;
> for(; i < b.length; i++) {
> el = b[i];
> if(el !== 3) {
> a[j++] = el;
> }
> }
> a.length = j;
> return a;
> }
>
> I can't see how using `splice` in a forwards loop would be a problem at
> all. I find that approach to be easy to understand and I use it in my
> own code.

Yes, repeat, such small questions just allow to test how will an
employee solve the issue, analyzing he's solution.

By the way, the example with an array and mentioning splice isn't good,
because splice will work. What I meant is removing e.g. child nodes from
some node and cashing length property for optimization with direct
(incremental) iteration. But, that's just an abstract small example ;)

Dmitry.