Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30891 > unrolled thread
| Started by | justaguy <lichunshen84@gmail.com> |
|---|---|
| First post | 2016-07-18 09:10 -0700 |
| Last post | 2016-07-19 16:16 -0300 |
| Articles | 20 on this page of 84 — 16 participants |
Back to article view | Back to comp.lang.javascript
How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 09:10 -0700
Re: How would you prepare for javascripting interview? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2016-07-18 18:37 +0200
Re: How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 11:09 -0700
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-07-21 01:04 +0000
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-07-21 14:24 +0100
Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-23 16:25 +0200
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-07-23 15:56 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-03 19:39 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-04 15:56 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 00:06 +0100
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-05 14:49 +0100
Re: How would you prepare for javascripting interview? $Bill <news@todbe.com> - 2016-09-05 10:01 -0700
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-06 09:36 -0700
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-05 15:05 +0100
Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-05 20:31 +0200
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-06 15:15 +0000
Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-06 19:40 +0200
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-06 19:25 +0100
Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-06 22:16 +0200
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-07 17:17 +0100
Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-07 20:07 +0200
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-08 14:36 +0100
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-05 18:46 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 20:32 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-05 17:27 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 20:12 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-06 16:48 +0000
Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-06 19:56 +0200
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-07 20:16 +0000
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-07 10:01 -0700
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-07 20:21 +0000
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-09 11:41 -0700
Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-09 15:35 -0700
Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-09 20:40 -0700
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-10 15:12 +0000
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-12 11:14 -0700
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-13 21:07 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-06 16:20 +0000
Re: How would you prepare for javascripting interview? Ken Tilton <kentilton@gmail.com> - 2016-09-05 11:37 -0700
Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-06 19:26 +0200
Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-08 12:41 -0700
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-05 20:37 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 22:13 +0100
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-06 02:33 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-06 16:02 +0000
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-06 09:50 -0700
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-07 01:36 +0000
Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-07 10:07 -0700
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 00:03 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 00:12 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-10 15:34 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-11 01:32 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-12 19:26 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-13 01:02 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-13 21:38 +0000
Re: How would you prepare for javascripting interview? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-09-14 00:56 +0200
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-15 15:09 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-14 00:47 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-15 15:34 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-11 02:45 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-12 19:10 +0000
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-12 21:06 +0100
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-07 03:12 +0000
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-07 19:53 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 02:14 +0000
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-10 11:25 +0100
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-10 15:49 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-10 18:39 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-11 02:45 +0000
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-11 16:23 +0100
Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-12 20:32 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-12 18:49 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-13 00:27 +0000
Re: How would you prepare for javascripting interview? Tim Streater <timstreater@greenbee.net> - 2016-09-13 08:51 +0100
Re: How would you prepare for javascripting interview? Jon Ribbens <jon+usenet@unequivocal.eu> - 2016-09-13 12:33 +0000
Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-14 01:17 +0000
Re: How would you prepare for javascripting interview? Tim Streater <timstreater@greenbee.net> - 2016-09-14 11:15 +0100
Re: How would you prepare for javascripting interview? Doc O'Leary <droleary@2015usenet1.subsume.com> - 2016-09-15 15:02 +0000
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-13 10:06 +0100
Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-06 19:53 +0100
Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-18 22:30 +0200
Re: How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 14:56 -0700
Re: How would you prepare for javascripting interview? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-07-19 16:01 -0300
Re: How would you prepare for javascripting interview? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-07-19 16:16 -0300
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-07-18 09:10 -0700 |
| Subject | How would you prepare for javascripting interview? |
| Message-ID | <bdc5226e-57a2-4987-bc11-7b6f563d208d@googlegroups.com> |
Let's supposed you're the interviewer. Thanks.
[toc] | [next] | [standalone]
| From | Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> |
|---|---|
| Date | 2016-07-18 18:37 +0200 |
| Message-ID | <d61qobd3n2o5t41c647v4075n2d429ub1j@4ax.com> |
| In reply to | #30891 |
On Mon, 18 Jul 2016 09:10:13 -0700 (PDT), justaguy wrote: >Let's supposed you're the interviewer. >Thanks. Apart from all other things, I would prepare a problem that each applicant has to solve by writing a relatively simple Javascript program. I would allow the applicants to have some language and DOM definition at hand, like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference . I would also have a competent Javascript programmer on hand to judge the results by judging the code's correctness, readability, and performance. Hans-Georg
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-07-18 11:09 -0700 |
| Message-ID | <50e38667-93da-4c5d-bc02-a78394f0ca3b@googlegroups.com> |
| In reply to | #30892 |
On Monday, July 18, 2016 at 12:37:22 PM UTC-4, Hans-Georg Michna wrote: > On Mon, 18 Jul 2016 09:10:13 -0700 (PDT), justaguy wrote: > > >Let's supposed you're the interviewer. > >Thanks. > > Apart from all other things, I would prepare a problem that each > applicant has to solve by writing a relatively simple Javascript > program. > > I would allow the applicants to have some language and DOM > definition at hand, like > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference > . > > I would also have a competent Javascript programmer on hand to > judge the results by judging the code's correctness, > readability, and performance. > > Hans-Georg " correctness, readability, and performance. ", it has to work (correct); it has to be able to be supported (readable); it has to be reasonably fast (performance). All makes sense. Thank you. And I saw the following prep test sets, https://www.sitepoint.com/5-typical-javascript-interview-exercises/ while I appreciate their effort I strongly dislike question #4, it's totally against Ocam's Razor's principle, if we can get the value of var fullname = 'John Doe' by console.log(fullname) why going the convoluted route?
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Date | 2016-07-21 01:04 +0000 |
| Message-ID | <nmp72g$4pc$1@dont-email.me> |
| In reply to | #30893 |
justaguy wrote:
> And I saw the following prep test sets,
> https://www.sitepoint.com/5-typical-javascript-interview-exercises/
> while I appreciate their effort I strongly dislike question #4,
(This is the example in question)
| What is the result of the following code? Explain your answer.
|
| var fullname = 'John Doe';
| var obj = {
| fullname: 'Colin Ihrig',
| prop: {
| fullname: 'Aurelio De Rosa',
| getFullname: function() {
| return this.fullname;
| }
| }
| };
|
| console.log(obj.prop.getFullname());
|
| var test = obj.prop.getFullname;
|
| console.log(test());
> it's totally against Ocam's Razor's principle,
> if we can get the value of var fullname = 'John Doe'
> by console.log(fullname) why going the convoluted route?
That entirely misses the point of the question. This does not ask how to
print "John Doe" to the console. It asks how a certain bit of code
behaves. The title should help explain it: "How `this` works in
JavaScript".
And the answer is that the same function behaves differently depending on
how it's invoked. Called as a method of the object `obj.prop`, the value
of `this` is that object. When it's called as a plain function, `this`
refers to the global object.
Questions 1 and 3 had the same format.
And the entire page is, IMHO, a waste of time.
When interviewing developers, I will ask questions designed to test the
depth of their knowledge, I will ask them to describe projects and
techniques, and I will have them write out some simple code. I have two
favorite bits. First, I present a really, really horrible bit of code
and ask them to note some of the things they see wrong with it; those who
skip over the more obvious and numerous surface flaws and go directly to
the poor choice of fundamental algorithm get my attention quickly. And
second, the only thing I have at all related to trick questions is
presented precisely as such. I only use this one with candidates who
have already demonstrated that they're fairly advanced. I present this
question and then help them figure their way through it, to determine how
well they can reason about this fairly simple, but surprising result just
through discussion: "It's a somewhat surprising fact that in Javascript,
Math.min() > Math.max(). Can you think of why this might be so?"
Other than that, I make sure I avoid trick questions, and that's really
not what this one is. I've never had someone answer it without guidance,
but some people take only a nudge or two, and for others I have to spell
it out entirely. This is not a deciding factor, but does help me form an
overall impression of a candidate.
I think questions like the ones on that site are designed to mostly pull
out minutiae rather than important questions about depth of knowledge.
They're a waste.
-- Scott
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-07-21 14:24 +0100 |
| Message-ID | <n5j1pblpd7nuhq7ali9vduffnpajuu5oul@4ax.com> |
| In reply to | #30953 |
On 21 Jul 2016 04:21:39 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote: >Scott Sauyet <scott@sauyet.com> writes: >>through discussion: "It's a somewhat surprising fact that in Javascript, >>Math.min() > Math.max(). Can you think of why this might be so?" > > A varargs operator (that is obtained from a binary operator) > over the empty set always gives the identity element of the > operation, because this is the most natural and useful definition. <snip> Dear me, you're doing a Thomas there! If your application wants the minimum of an empty list to be undefined then that's perfectly legitimate. Even if it is defined it might be inconvenient to define it as zero. Minus infinity is an alternative. Of course, that isn't a number, so you might want to name it 'undefined' instead. John
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-07-23 16:25 +0200 |
| Message-ID | <1875389.irdbgypaU6@PointedEars.de> |
| In reply to | #30953 |
Stefan Ram wrote:
> Scott Sauyet <scott@sauyet.com> writes:
>>through discussion: "It's a somewhat surprising fact that in Javascript,
>>Math.min() > Math.max(). Can you think of why this might be so?"
>
> A varargs operator (that is obtained from a binary operator)
> over the empty set always gives the identity element of the
> operation, because this is the most natural and useful definition.
>
> For example, we can say that the sum of a list of numbers
> a, b, c, can be written as
>
> 0 + a + b + c
>
> where there is a substring »+ x« for every member of the list.
>
> So, we have to rule to append » + x« to »0« for each member »x«.
>
> The binary operator »+« is not defined for just one operand
> or no operand, but our list operator (varargs operator) needs to be.
>
> When there is only one member a in the list, the rule given
> above results in
>
> 0 + a
>
> , when the list is empty we just get
>
> 0
>
> , the identity element.
[What on Earth is the relation of this to the question at hand?]
The reason for the aforementioned fact is that Math.min() returns Infinity
and Math.max() returns -Infinity. And – need I spell it out? –
Infinity > -Infinity.
It makes sense for a minimum function to iterate over an argument list
starting with the highest possible value, and for a maximum function with
the lowest possible value. Were one to implement the methods (according
to ECMAScript Ed. 3 and later), they would be (quickhack):
if (Math.min(2, 3, 1) > 1)
{
Math.min = function () {
var result = Infinity;
for (var i = 0, len = arguments.length; i < len; ++i)
{
var arg = +arguments[i];
/* NaN is the only Number value not equal to itself */
if (arg != arg) return Number.NaN;
if (arg < result) result = arg;
}
return result;
};
Math.min.length = 2;
}
if (Math.max(1, 2, 3) < 3)
{
Math.max = function () {
var result = -Infinity;
for (var i = 0, len = arguments.length; i < len; ++i)
{
var arg = +arguments[i];
if (arg != arg) return Number.NaN;
if (arg > result) result = arg;
}
return result;
};
Math.max.length = 2;
}
<http://www.ecma-international.org/ecma-262/6.0/#sec-math.max>
BTDT (there have been implementations that did not support more than two
arguments, and tail recursion is inefficient in this case).
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-07-23 15:56 +0000 |
| Message-ID | <nn044b$e69$1@dont-email.me> |
| In reply to | #30966 |
For your reference, records indicate that Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: > It makes sense for a minimum function to iterate over an argument list > starting with the highest possible value, and for a maximum function with > the lowest possible value. Not really. It makes very little sense to return a “valid” result as output that was not part of the input arguments. That’s certainly one, lazy way to define the function based on a convenient, number-centric implementation. For many other languages, min/max functions are often generically implemented on collections of comparable objects. On an empty list, they usually return a null object. What might also make sense is “undefined”, but not an opposite infinity. So would I get the job, or would you hire a more “agreeable” developer? :-) -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Date | 2016-09-03 19:39 +0000 |
| Message-ID | <nqf8t7$h37$1@dont-email.me> |
| In reply to | #30967 |
Doc O'Leary wrote:
> Thomas 'PointedEars' Lahn wrote:
>> It makes sense for a minimum function to iterate over an argument list
>> starting with the highest possible value, and for a maximum function
>> with the lowest possible value.
>
> Not really. It makes very little sense to return a “valid” result as
> output that was not part of the input arguments. That’s certainly one,
> lazy way to define the function based on a convenient, number-centric
> implementation.
Remember that the context was the functions `Math.max` and `Math.min`, so
a number-centric implementation makes perfect sense.
If we were trying to implement something with a signature such as
// min :: Ord a => [a] -> a
we would probably run into an issue in precisely the case when an empty
list is supplied. We might be better creating
// min :: Ord a => [a] -> Maybe a
> For many other languages, min/max functions are often
> generically implemented on collections of comparable objects. On an
> empty list, they usually return a null object. What might also make
> sense is “undefined”, but not an opposite infinity.
A null object or undefined have significant disadvantages that they are
not of the right type. Downstream code will need to type-check the
result if the function is designed like that.
> So would I get the job, or would you hire a more “agreeable” developer?
> :-)
An answer like that would absolutely capture my attention. If you
demonstrated that you understood why it works like it does and noted
reasonable alternatives, it would be a very good sign. Even if you used
this to spring into a discussion of the defects in the language design, I
would still be happy, just so long as you are then able to come back down
to earth and discuss other issues I bring up.
-- Scott
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-04 15:56 +0000 |
| Message-ID | <nqhg6o$st6$1@dont-email.me> |
| In reply to | #31223 |
For your reference, records indicate that Scott Sauyet <scott@sauyet.com> wrote: > Remember that the context was the functions `Math.max` and `Math.min`, so > a number-centric implementation makes perfect sense. No, it doesn’t. It makes *zero* sense for either function to return a number that wasn’t in the input set. That’s just a bad decision in the language’s design. It also creates an inconsistent behavior if they every *do* want to add such functions for other data types. > A null object or undefined have significant disadvantages that they are > not of the right type. Downstream code will need to type-check the > result if the function is designed like that. They’ll have to do worse if they expect to function correctly based on the current behavior. You could perhaps raise it as an exception if you prefer, but it’s just plain *wrong* to return a number that wasn’t given to you. That’s why this behavior makes for a suitable trick question, but a terrible one for finding a JavaScript developer that actually thinks about the work they’re doing. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-05 00:06 +0100 |
| Message-ID | <87h99vz2lp.fsf@bsb.me.uk> |
| In reply to | #31227 |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Doc O'Leary <droleary@2015usenet1.subsume.com> writes:
>>They'll have to do worse if they expect to function correctly based
>>on the current behavior. You could perhaps raise it as an exception
>>if you prefer, but it's just plain *wrong* to return a number that
>>wasn't given to you.
>
> |> 5 ** 0
> |< 1
>
> Why does it evaluate to 1?
>
> 5³ = 5 · 5 · 5 = 125
>
> 5² = 5 · 5 = 25
>
> 5¹ = 5 = 5
>
> 5° = = 1, why??
Lots of reasons... you want 5**x to be continuous (for real x)... you
want 5**a x 5**b = 5 ** (a+b)... and so on.
> There were three operands in the multiplication in the case of »5³«,
> there were two operands in the multiplication in the case of »5²«,
> there was still one number ("operand") left in the case of »5¹«,
> but there is /no/ operand in the case of »5°«, so why is it 1?
Here I think you want to draw attention to the fact that 1 is the
multiplicative identity...
> When you find the answer to this riddle,
> then you will also understand the reason for
>
> |> Math.max()
> |< -Infinity
... and -Infinity is the "max identity". Is that your point?
I don't think anyone is wondering *why* Math.max() = -Infinity so much
as whether it should be anything at all.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-09-05 14:49 +0100 |
| Message-ID | <ittqsbt1sc5au1cabb0oib47gi1em329or@4ax.com> |
| In reply to | #31229 |
On 4 Sep 2016 23:54:14 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote: <snip> > If I would be a teacher in an elementary school, > I would explain it as follows: "x ** n" means > "1 multiplied n times with x", this is /correct/ > and gives the correct value in /all/ cases. A better explanation is that x**0.000001 is very nearly 1. John
[toc] | [prev] | [next] | [standalone]
| From | $Bill <news@todbe.com> |
|---|---|
| Date | 2016-09-05 10:01 -0700 |
| Message-ID | <nqk8do$eov$1@dont-email.me> |
| In reply to | #31232 |
On 09-05-16 07:08, Stefan Ram wrote: > John Harris <niam@jghnorth.org.uk.invalid> writes: >> On 4 Sep 2016 23:54:14 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote: >>> If I would be a teacher in an elementary school, >>> I would explain it as follows: "x ** n" means >>> "1 multiplied n times with x", this is /correct/ >>> and gives the correct value in /all/ cases. >> A better explanation is that x**0.000001 is very nearly 1. > > And how do you explain /that/ in elementary school? They didn't explain it in mine - it was a given that any number raised to the zero power is equal to one. You get to explaining that much later.
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2016-09-06 09:36 -0700 |
| Message-ID | <93stsb1icrkiljo2hc65njj0v6m0edfoc8@4ax.com> |
| In reply to | #31232 |
On Mon, 05 Sep 2016 14:49:49 +0100, John Harris
<niam@jghnorth.org.uk.invalid> wrote:
>On 4 Sep 2016 23:54:14 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote:
>
> <snip>
>> If I would be a teacher in an elementary school,
>> I would explain it as follows: "x ** n" means
>> "1 multiplied n times with x", this is /correct/
>> and gives the correct value in /all/ cases.
>
>A better explanation is that x**0.000001 is very nearly 1.
A much worse one. Explaining exponentiation to an integer value
by dragging in exponentiation to a real value is putting the cart
before the horse.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-09-05 15:05 +0100 |
| Message-ID | <2puqsbta8crtl2lthb1c63dpkqohbgtq0m@4ax.com> |
| In reply to | #31229 |
On 5 Sep 2016 00:23:20 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote: <snip> > When we want > this property even for /no/ arguments, e.g., in the case > >max( max( a, b, c, d ), max( e ))= max( max( a, b, c, d, e ), max() ) > > , it dictates that "max()" must be "-Infinity". <snip> I recently found a circumstance where the correct thing to do was to declare that max() = -1. The correct answer to the question is that it depends on the context. Any other answer is seriously wrong. For your next problem, what should max be when given an infinite collection of different numbers? It can't be a finite number because that would be less than some of the numbers in the collection. It can't be an infinite number because that would be bigger than any of the numbers in the collection. John
[toc] | [prev] | [next] | [standalone]
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Date | 2016-09-05 20:31 +0200 |
| Message-ID | <nqkdlb$nj0$1@news.albasani.net> |
| In reply to | #31233 |
John Harris wrote: > I recently found a circumstance where the correct thing to do was to > declare that max() = -1. Can you share more about that use case, please? > The correct answer to the question is that it depends on the context. > Any other answer is seriously wrong. Surely the context for `Math.max` are JavaScript's floating point numbers, in which -Infinity is the identity element for the maximum operation. > For your next problem, what should max be when given an infinite > collection of different numbers? It can't be a finite number because > that would be less than some of the numbers in the collection. It > can't be an infinite number because that would be bigger than any of > the numbers in the collection. If you pass in an infinite collection, the function will not terminate. Treat it like returning bottom (or throwing an exception or something). - Bergi
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-06 15:15 +0000 |
| Message-ID | <nqmmjb$70t$1@dont-email.me> |
| In reply to | #31238 |
For your reference, records indicate that Andreas Bergmaier <andber93@web.de> wrote: > John Harris wrote: > > > I recently found a circumstance where the correct thing to do was to > > declare that max() = -1. > > Can you share more about that use case, please? My guess at it would be something where the range was restricted to positive integers (e.g., array index), thus a negative number signifies some sort of error condition. > > For your next problem, what should max be when given an infinite > > collection of different numbers? It can't be a finite number because > > that would be less than some of the numbers in the collection. It > > can't be an infinite number because that would be bigger than any of > > the numbers in the collection. > > If you pass in an infinite collection, the function will not terminate. Nah, you just need a different programming paradigm. I can, for example, easily define a function that returns a maximum prime number, but it’ll just be the maximum that had been calculated at the time the function was called. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-09-06 19:40 +0200 |
| Message-ID | <5196662.lOV4Wx5bFT@PointedEars.de> |
| In reply to | #31238 |
Andreas Bergmaier wrote: > John Harris wrote: >> The correct answer to the question is that it depends on the context. >> Any other answer is seriously wrong. > > Surely the context for `Math.max` are JavaScript's floating point > numbers, in which -Infinity is the identity element for the maximum > operation. It can be argued that “-Infinity” and “Infinity” are Number values like any other, and, due to the specified algorithm, there is no difference between the return value when only “-Infinity” or “Infinity” are passed to Math.max() and Math.min() respectively, and when the same functions are called with an empty argument list. As for the “return type” argument, “NaN” also is a Number value that could be returned here to indicate a difference. Returning “null” instead would have the advantage of being clearly not a Number value, allowing to tell apart Math.max(NaN) and Math.max(), and Math.min(…) calls respectively. Or a (TypeError) exception could be thrown; after all, the methods are expected to return the maximum and minimum element of a set of Number values. The empty set contains no suitable element because it contains no elements at all. >> For your next problem, what should max be when given an infinite >> collection of different numbers? It can't be a finite number because >> that would be less than some of the numbers in the collection. It >> can't be an infinite number because that would be bigger than any of >> the numbers in the collection. > > If you pass in an infinite collection, the function will not terminate. > Treat it like returning bottom (or throwing an exception or something). There are no *explicit* infinite collections in programming languages. (We have discussed how you can construct predicates for infinite sets, but that is an *implicit* definition.) -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-09-06 19:25 +0100 |
| Message-ID | <de2usbdk03vrhgleffovaitgaeberuqb2j@4ax.com> |
| In reply to | #31238 |
On Mon, 5 Sep 2016 20:31:08 +0200, Andreas Bergmaier <andber93@web.de> wrote: >John Harris wrote: > >> I recently found a circumstance where the correct thing to do was to >> declare that max() = -1. > >Can you share more about that use case, please? <snip> Consider a finite tree. For any node, t, there are one or more paths that go from a leaf node to t. Each path has a length, namely the number of steps needed to reach t from the path's leaf node. Problem : Specify and implement a function that given a node, t, returns the length of the longest path to t. Specification : Specify the function recursively. Here are two versions : A Given any node t if t is a leaf node then MaxPathLen(t) = 0 else MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t) B Given any node t MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t) Specify and implement max so that max() = -1 Version A carefully avoids the max() horror. Version B uses a max function carefully tuned to the needs of this kind of use. John
[toc] | [prev] | [next] | [standalone]
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Date | 2016-09-06 22:16 +0200 |
| Message-ID | <nqn86l$kam$1@news.albasani.net> |
| In reply to | #31258 |
John Harris wrote: > A > Given any node t > if t is a leaf node > then MaxPathLen(t) = 0 > else MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t) > > B > Given any node t > MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t) > Specify and implement max so that max() = -1 > > Version A carefully avoids the max() horror. Which is quite sensible and makes the code more readable to most of us. "Leaf" and "Node", in many tree implementations represented by different classes, are two separate cases to be handled, and the primitive recursion pattern is obvious in this phrasing of the algorithm. > Version B uses a max function carefully tuned to the needs of this > kind of use. "Carefully tuned" seems to mean "custom-built for the arbitrary requirements" :-D If I had to implement this, I would use the `max` function on non-negative integers (the type of path lengths), whose identity element is 0. It would then read MaxPathLen(t) = max(MathPathLen(c) + 1 foreach c of the children of t) In Haskell for example you'd use this quite literally: maximum :: (Bounded a, Ord a, Foldable f) => f a -> a maximum = foldl' max minBound data Tree a = Node a [Tree a] -- data type for rose trees maxDepth :: Tree a -> Word -- `Word` is the unsigned integer type maxDepth (Node _ children) = maximum [maxDepth c + 1, c <- children] - Bergi
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-09-07 17:17 +0100 |
| Message-ID | <7af0tbt8dnb5tu6ul3pt1dtkfc3l813h7r@4ax.com> |
| In reply to | #31261 |
On Tue, 6 Sep 2016 22:16:23 +0200, Andreas Bergmaier <andber93@web.de>
wrote:
>John Harris wrote:
>
>> A
>> Given any node t
>> if t is a leaf node
>> then MaxPathLen(t) = 0
>> else MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t)
>>
>> B
>> Given any node t
>> MaxPathLen(t) = 1 + max(MaxPathLen(c) of the children, c, of t)
>> Specify and implement max so that max() = -1
>>
>> Version A carefully avoids the max() horror.
>
>Which is quite sensible and makes the code more readable to most of us.
>"Leaf" and "Node", in many tree implementations represented by different
>classes, are two separate cases to be handled, and the primitive
>recursion pattern is obvious in this phrasing of the algorithm.
I also think it's clearer. In addition, it reminds the implementors
that they must recognise leaf nodes and not recurse any further, else
disaster.
>> Version B uses a max function carefully tuned to the needs of this
>> kind of use.
>
>"Carefully tuned" seems to mean "custom-built for the arbitrary
>requirements" :-D
Custom built : yes. Arbitrary : how can a project's needs be called
arbitrary?
>If I had to implement this, I would use the `max` function on
>non-negative integers (the type of path lengths), whose identity element
>is 0. It would then read
>
> MaxPathLen(t) = max(MathPathLen(c) + 1 foreach c of the children of t)
<snip>
That's a third way to specify the function, but max() is still
"custom-built for the arbitrary requirements" :-D
Concerning identity elements, can you explain their possible
significance here. To me, an identity element, e, is defined by
x op e = x
not by
op e = e
(no x), or
op = e
(no anything).
John
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web