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 2 of 5 — ← Prev page 1 [2] 3 4 5 Next page →
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Date | 2016-09-07 20:07 +0200 |
| Message-ID | <nqpl1g$6oc$1@news.albasani.net> |
| In reply to | #31266 |
John Harris wrote:
>> 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
Nah, I used the very generic `maximum` function that you snipped away :-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).
Yes. In the case where `op` is the maximum of two floating point
numbers, we have
Math.max(x, -Infinity) == x
(and
Math.max(-Infinity, x) == x
because it's commutative)
Only if we have a variadic function, or - if properly typed - one that
takes a list/set/collection of elements, it does become significant.
We would define
function max(a, b) {
return a > b ? a : b;
}
function maximum(args) {
if (args.length == 0)
return -Infinity;
else
return max(args[0], maximum(args.slice(1)));
}
Math.max = function(...args) { return maximum(args) };
// or simply
Math.max = function(...args) { return args.reduce(max, -Infinity); };
- Bergi
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-09-08 14:36 +0100 |
| Message-ID | <i7q2tb9ff2m90dpva4s769qpknie6hv3r4@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. > >> 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) It now occurs to me that there is yet another specification of MaxPathLen that has a different way of using max, a way that nullifies all arguments about identity values and arbitrary values. Instead of writing max(), max(a), max(a, b), max(a, b, c), ... write max(z), max(z, a), max(z, a, b), max(z, a, b, c), ... where z is your favourite identity value or required arbitrary value. Then I would write Given any node t MaxPathLen(t) = 1 + max(-1, MaxPathLen(c) of the children, c, of t) and you would write MaxPathLen(t) = max(0, MathPathLen(c) + 1 foreach c of the children of t) Then in an ECMAScript program a result of -infinity would indicate a serious programming error. John
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Date | 2016-09-05 18:46 +0000 |
| Message-ID | <nqkeis$a5g$1@dont-email.me> |
| In reply to | #31233 |
John Harris wrote: > 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. Well, it's easy enough to imagine an infinite collection, say, of all the positive rational numbers whose squares are less than 2. There's an obvious finite maximum in the real numbers, sqrt(2). See Dedekind cuts for more information. [1] But none of this has to do with programming. This is the realm of pure mathematics now. [1]: E.g.: <https://en.wikipedia.org/wiki/Dedekind_cut> -- Scott
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-09-05 20:32 +0100 |
| Message-ID | <87twduxhv1.fsf@bsb.me.uk> |
| In reply to | #31240 |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Scott Sauyet <scott@sauyet.com> writes:
>>Well, it's easy enough to imagine an infinite collection, say, of all the
>>positive rational numbers whose squares are less than 2. There's an
>>obvious finite maximum in the real numbers, sqrt(2). See Dedekind cuts
>>for more information. [1]
>
> /Supremum/. The /maximum/ of a set is an /element/ of that set,
> but sqrt(2) is not a number whose square is /less than/ 2.
Curiously, you've been arguing for a definition of maximum where it may
/not/ be an element of the set.
Further, when sup is defined on the extended reals (R U {-oo, +oo}) so
that sup R = oo, it makes sense to define sup {} = -oo (and some authors
actually do this).
So here you seem to arguing that Math.max() = -Infinity is wrong because
the maximum of a set is an element of that set, but there should be a
Math.sup() whose value is -Infinity.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-05 17:27 +0000 |
| Message-ID | <nqk9ug$kms$1@dont-email.me> |
| In reply to | #31229 |
For your reference, records indicate that Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > I don't think anyone is wondering *why* Math.max() = -Infinity so much > as whether it should be anything at all. Or, more to the point, why it isn’t defined as something that is *conceptually consistent* with other methods for calculating it, including how it might be treated for other data types. For example, if you put the numbers in an array, you might be tempted to use something like reduce() to get down to the min/max value. Try that on an empty array and you get a TypeError. If you instead think of it as a sort() followed by an unshift() or pop(), trying to do it that way on an empty array returns undefined. There are probably many other similar *sensible* ways to do the operation, and *none* of them will pull an infinity out of nowhere like the Math functions do. It’s an implementation hack that should have been fixed as the language matured. Nobody who defends the choice should ever get *any* work in Computer Science, let alone a JavaScript job. -- "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 20:12 +0100 |
| Message-ID | <87zinmxis5.fsf@bsb.me.uk> |
| In reply to | #31236 |
Doc O'Leary <droleary@2015usenet1.subsume.com> writes: > For your reference, records indicate that > Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > >> I don't think anyone is wondering *why* Math.max() = -Infinity so much >> as whether it should be anything at all. > > Or, more to the point, why it isn’t defined as something that is > *conceptually consistent* with other methods for calculating it, > including how it might be treated for other data types. > > For example, if you put the numbers in an array, you might be > tempted to use something like reduce() to get down to the min/max > value. Try that on an empty array and you get a TypeError. If you > instead think of it as a sort() followed by an unshift() or pop(), > trying to do it that way on an empty array returns undefined. These are valid points (though you can reduce an empty array provided you specify the "identity"). But I wonder if you feel the same about: > [].every(x=>x) true > [].some(x=>x) false And would you object to [].sum() being 0 and [].product being 1? (I know ECMAScript has neither, I'm just interested in how you see similar situations.) > There are probably many other similar *sensible* ways to do the > operation, and *none* of them will pull an infinity out of nowhere > like the Math functions do. It’s an implementation hack that > should have been fixed as the language matured. Nobody who defends > the choice should ever get *any* work in Computer Science, let > alone a JavaScript job. I was with you up to this point. The infinity is not pulled out of nowhere -- there's a reason for it, even if you don't think it's a good one (or a good enough one). And even if you disagree with the choice, it's certainly not a hack, and defending it is no reason be barred from working with JavaScript. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-06 16:48 +0000 |
| Message-ID | <nqms14$v6r$1@dont-email.me> |
| In reply to | #31242 |
For your reference, records indicate that Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > Doc O'Leary <droleary@2015usenet1.subsume.com> writes: > > > For your reference, records indicate that > > Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > > > >> I don't think anyone is wondering *why* Math.max() = -Infinity so much > >> as whether it should be anything at all. > > > > Or, more to the point, why it isn’t defined as something that is > > *conceptually consistent* with other methods for calculating it, > > including how it might be treated for other data types. > > > > For example, if you put the numbers in an array, you might be > > tempted to use something like reduce() to get down to the min/max > > value. Try that on an empty array and you get a TypeError. If you > > instead think of it as a sort() followed by an unshift() or pop(), > > trying to do it that way on an empty array returns undefined. > > These are valid points (though you can reduce an empty array provided > you specify the "identity"). Yes, you can reduce it to *anything* if you supply that anything! We both know the issue is bigger than that. > But I wonder if you feel the same about: > > > [].every(x=>x) > true > > [].some(x=>x) > false I would say there should *definitely* have been a debate on those choices as default values, too. At a higher level, it doesn’t make sense to say that something is true for *every* object in a collection, but it is *not* true for some of them. > And would you object to [].sum() being 0 and [].product being 1? (I > know ECMAScript has neither, I'm just interested in how you see similar > situations.) A sum does essentially start at zero, so I have no objection to that. I don’t know any mathematical concept of a product that can similarly be said to have a set value. > I was with you up to this point. The infinity is not pulled out of > nowhere -- there's a reason for it, even if you don't think it's a good > one (or a good enough one). And even if you disagree with the choice, > it's certainly not a hack, and defending it is no reason be barred from > working with JavaScript. Sorry, but it’s just a dirty hack. It’s used as the default value simply because the implementation makes it a convenient comparison, what with *any* value being greater than -Infinity (or the opposite for min). But any actual thought to the *meaning* of the operations would lead any competent developer to a different solution, and one that provides a sensible result for an empty set *regardless* of the type of object that it contains none of. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Date | 2016-09-06 19:56 +0200 |
| Message-ID | <nqn005$4vv$1@news.albasani.net> |
| In reply to | #31253 |
Doc O'Leary wrote: > Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > >> But I wonder if you feel the same about: >> >> > [].every(x=>x) >> true >> > [].some(x=>x) >> false > > I would say there should *definitely* have been a debate on those > choices as default values, too. There's no need for debate. `true` and `false` are the identity values for the AND and OR operations. > At a higher level, it doesn’t make > sense to say that something is true for *every* object in a > collection, but it is *not* true for some of them. Well, you won't find any object in the empty collection for which it is not true. May I refer you to https://en.wikipedia.org/wiki/Vacuous_truth? >> And would you object to [].sum() being 0 and [].product being 1? (I >> know ECMAScript has neither, I'm just interested in how you see similar >> situations.) > > A sum does essentially start at zero, so I have no objection to that. > I don’t know any mathematical concept of a product that can similarly > be said to have a set value. Not knowing about something doesn't imply it would not exist :-) The identity element of multiplication is 1. Have a look at https://en.wikipedia.org/wiki/Empty_product for further discussion. - Bergi
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-07 20:16 +0000 |
| Message-ID | <nqpsjd$qjs$1@dont-email.me> |
| In reply to | #31257 |
For your reference, records indicate that Andreas Bergmaier <andber93@web.de> wrote: > There's no need for debate. `true` and `false` are the identity values > for the AND and OR operations. Which has absolutely *no* bearing on what these functions should return *to the caller*. I don’t give a damn whether or not they use identities internally just like Math does for max/min. What I care about is if they *output* a result that doesn’t make sense across their range of input. > > At a higher level, it doesn’t make > > sense to say that something is true for *every* object in a > > collection, but it is *not* true for some of them. > > Well, you won't find any object in the empty collection for which it is > not true. And I bet you’re the kind of guy that also thinks he’s being clever when asked “Soup or salad?” in a restaurant and you reply “Yes!” > May I refer you to https://en.wikipedia.org/wiki/Vacuous_truth? The operative word to focus on there is not “truth” but “vacuous”. I strive to write programs that are more than vacuous. Care to join me? > >> And would you object to [].sum() being 0 and [].product being 1? (I > >> know ECMAScript has neither, I'm just interested in how you see similar > >> situations.) > > > > A sum does essentially start at zero, so I have no objection to that. > > I don’t know any mathematical concept of a product that can similarly > > be said to have a set value. > > Not knowing about something doesn't imply it would not exist :-) The > identity element of multiplication is 1. Again, this has nothing to do with mathematical identities and everything to do with competent computer science and engineering complex systems. *No* regular person sees a product/multiplication as an operation on anything less than 2 numbers. Saying “But I know how to get an answer all the way down to 0 numbers!” doesn’t make you a good developer, it makes you some who shouldn’t be working in a field outside of pure math. The better CS argument is not that product() should be 1, but that we shouldn’t even allow sum() to default to 0. But even as a CS argument that can be a tough sell, because we coerce so *very* many zero-like values to 0 already. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2016-09-07 10:01 -0700 |
| Message-ID | <ash0tblm997jpd5cgnoj2decctpmk0m9iu@4ax.com> |
| In reply to | #31253 |
On Tue, 6 Sep 2016 16:48:36 -0000 (UTC), Doc O'Leary
<droleary@2015usenet1.subsume.com> wrote:
[snip]
>A sum does essentially start at zero, so I have no objection to that.
>I don’t know any mathematical concept of a product that can similarly
>be said to have a set value.
A product "starts" at one.
Examples are 0th powers and 0! which are all 1 (except 0 to the 0
which is undefined).
[snip]
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-07 20:21 +0000 |
| Message-ID | <nqpssb$qjs$2@dont-email.me> |
| In reply to | #31268 |
For your reference, records indicate that Gene Wirchenko <genew@telus.net> wrote: > On Tue, 6 Sep 2016 16:48:36 -0000 (UTC), Doc O'Leary > <droleary@2015usenet1.subsume.com> wrote: > > [snip] > > >A sum does essentially start at zero, so I have no objection to that. > >I dont know any mathematical concept of a product that can similarly > >be said to have a set value. > > A product "starts" at one. No, it doesn’t. It certainly has 1 as its identity, but that’s not the same thing. Do yourself a favor and talk to real people about their understanding of math before you *ever* write any software you expect them to use on a daily basis. A fun thought experiment: what was the identity element for the addition operation before 0 was invented? :-) -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2016-09-09 11:41 -0700 |
| Message-ID | <ka06tblb67n5dscqrtjs83f9i16vf6ii0l@4ax.com> |
| In reply to | #31273 |
On Wed, 7 Sep 2016 20:21:31 -0000 (UTC), Doc O'Leary
<droleary@2015usenet1.subsume.com> wrote:
>For your reference, records indicate that
>Gene Wirchenko <genew@telus.net> wrote:
>
>> On Tue, 6 Sep 2016 16:48:36 -0000 (UTC), Doc O'Leary
>> <droleary@2015usenet1.subsume.com> wrote:
>>
>> [snip]
>>
>> >A sum does essentially start at zero, so I have no objection to that.
>> >I don?t know any mathematical concept of a product that can similarly
>> >be said to have a set value.
>>
>> A product "starts" at one.
>
>No, it doesn’t. It certainly has 1 as its identity, but that’s not
Actually, it does. When you initialise for a chain
multiplication, the initialisation value is 1.
>the same thing. Do yourself a favor and talk to real people about
>their understanding of math before you *ever* write any software you
>expect them to use on a daily basis.
Oh, I have. I minored in math. Number theory is a particular
interest of mine.
>A fun thought experiment: what was the identity element for the
>addition operation before 0 was invented? :-)
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2016-09-09 15:35 -0700 |
| Message-ID | <ec5639ca-76d6-4fcd-9866-34582b7a945a@googlegroups.com> |
| In reply to | #31291 |
Doc O'Leary wrote: > A fun thought experiment: what was the identity element for the addition operation before 0 was invented? :-) Undefined. Such an understandimg and theory of Alhebraic structures came after the discovery of zero. (Galios and Group Theory)
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2016-09-09 20:40 -0700 |
| Message-ID | <3fb425d1-ca11-4594-a6cd-f615b02d99a3@googlegroups.com> |
| In reply to | #31292 |
On Friday, September 9, 2016 at 5:36:19 PM UTC-5, Michael Haufe (TNO) wrote: > Doc O'Leary wrote: > > A fun thought experiment: what was the identity element for the addition operation before 0 was invented? :-) > > Undefined. Such an understandimg and theory of Alhebraic structures came after the discovery of zero. (Galios and Group Theory) s/Alhebraic/Algebraic
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-10 15:12 +0000 |
| Message-ID | <nr17sk$2ar$1@dont-email.me> |
| In reply to | #31291 |
For your reference, records indicate that Gene Wirchenko <genew@telus.net> wrote: > On Wed, 7 Sep 2016 20:21:31 -0000 (UTC), Doc O'Leary > > > >No, it doesnt. It certainly has 1 as its identity, but thats not > > Actually, it does. When you initialise for a chain > multiplication, the initialisation value is 1. > > >the same thing. Do yourself a favor and talk to real people about > >their understanding of math before you *ever* write any software you > >expect them to use on a daily basis. > > Oh, I have. I minored in math. Number theory is a particular > interest of mine. So who are the non-math-geeks you talk with that describe multiplication as something you “initialize” in a “chain”? I continue to state the obvious to not only the vast majority of the population, but the correct behavior from a *computer science* perspective: anyone calling a commonly binary function with less than 2 values is probably doing so in error. Nobody but mathematicians care how clever it is that you can still fabricate a “valid” result with 0 arguments. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@telus.net> |
|---|---|
| Date | 2016-09-12 11:14 -0700 |
| Message-ID | <b2sdtbt92f2n63ub7sltd0d9350onfbg87@4ax.com> |
| In reply to | #31304 |
On Sat, 10 Sep 2016 15:12:20 -0000 (UTC), Doc O'Leary
<droleary@2015usenet1.subsume.com> wrote:
[snip]
>So who are the non-math-geeks you talk with that describe
>multiplication as something you “initialize” in a “chain”? I
>continue to state the obvious to not only the vast majority of the
>population, but the correct behavior from a *computer science*
>perspective: anyone calling a commonly binary function with less
>than 2 values is probably doing so in error. Nobody but
>mathematicians care how clever it is that you can still fabricate a
>“valid” result with 0 arguments.
Since it is mathematics, maybe you should pay attention to how
mathematicians define it.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-13 21:07 +0000 |
| Message-ID | <nr9pqm$22i$1@dont-email.me> |
| In reply to | #31341 |
For your reference, records indicate that Gene Wirchenko <genew@telus.net> wrote: > Since it is mathematics, maybe you should pay attention to how > mathematicians define it. If you know neither computer science nor mathematics, and are unwilling to seek out even common references, you probably should remain silent. “As defined in set theory, the maximum and minimum of a set are the greatest and least elements in the set, respectively.” <https://en.wikipedia.org/wiki/Maxima_and_minima> An empty set contains *no* elements. That max/min have an identity is *irrelevant* to what should be returned. It is not an element *in* the input set, and so it should not be returned as the output element. This is the last time I’m going to bother repeating what should be obvious. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Doc O'Leary <droleary@2015usenet1.subsume.com> |
|---|---|
| Date | 2016-09-06 16:20 +0000 |
| Message-ID | <nqmqc1$osv$1@dont-email.me> |
| In reply to | #31236 |
For your reference, records indicate that ram@zedat.fu-berlin.de (Stefan Ram) wrote: > Doc O'Leary <droleary@2015usenet1.subsume.com> writes: > >For example, if you put the numbers in an array, you might be > >tempted to use something like reduce() to get down to the min/max > >value. Try that on an empty array and you get a TypeError. > > Works here: > > |> const a = []; > |> console.log( a.reduce( (x,y)=>Math.max(x,y), -Infinity )); > | -Infinity > > |> const a = [ -9, 12, 2 ]; > |> console.log( a.reduce( (x,y)=>Math.max(x,y), -Infinity )); > | 12 So you not only *supply* the infinity, but also use the Math.max() that is known to improperly supply it as well, and you think that validates your position? At this point, it’s clear you’re just trolling. -- "Also . . . I can kill you with my brain." River Tam, Trash, Firefly
[toc] | [prev] | [next] | [standalone]
| From | Ken Tilton <kentilton@gmail.com> |
|---|---|
| Date | 2016-09-05 11:37 -0700 |
| Message-ID | <c6f0b8e1-d71f-42a0-881d-9c41d917eba5@googlegroups.com> |
| In reply to | #31229 |
On Sunday, September 4, 2016 at 7:07:06 PM UTC-4, Ben Bacarisse wrote: > 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. Good one. Also, 5**a / 5**a = 1 = 5**(a-a) = 5**0. So an aside to the OP: note that we are talking about maths, not Javascript. Over on c.l.lisp a troll asked for an apples and oranges justification. I pointed out that two oranges in two dimensions is four oranges arrange in a square. In three dimensions we have a second layer of four oranges or eight. In one dimension we have a line of two oranges. In zero dimensions we have one pointillist orange. hth, kt
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-09-06 19:26 +0200 |
| Message-ID | <4969607.DvuYhMxLoT@PointedEars.de> |
| In reply to | #31229 |
Stefan Ram wrote: > If I would be a teacher in an elementary school, Let us hope that you never will. You are insufficiently talented for teaching. > I would explain it as follows: "x ** n" means > "1 multiplied n times with x", this is /correct/ No, it is not. You mean something else. > and gives the correct value in /all/ cases. If your wording is corrected. However, this is where natural language is starting to fail to describe precisely, and it is simpler and better to give the mathematical definition, x⁰ := 1, instead. [Please do not use the degree symbol and other replacements for the correct characters; if you are arguing in favor of correctness, you should use *correct* symbols *and* punctuation, including those from the rich character set provided by Unicode, if necessary – ⁰, ∑, and ∏ –, and in Germanic languages like English a sentence-ending mark, for example, is *never* preceded by whitespace. (Also, indentation should be the exception, not the default.)] -- 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]
Page 2 of 5 — ← Prev page 1 [2] 3 4 5 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web