Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: How would you prepare for javascripting interview? Date: Tue, 13 Sep 2016 01:02:27 +0100 Organization: A noiseless patient Spider Lines: 57 Message-ID: <87mvjcr7jg.fsf@bsb.me.uk> References: <50e38667-93da-4c5d-bc02-a78394f0ca3b@googlegroups.com> <1875389.irdbgypaU6@PointedEars.de> <9cstsb1uddjiltlflrdiks2ha2u3msi1ao@4ax.com> <87d1kbtgxn.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="12781"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JviHk+hSNrwgMx8NAMfOFl2vFAF+0Qgo=" Cancel-Lock: sha1:DViYil117XYCh0PYeJBkjRmCN3M= sha1:UdGw6YXnNWRyBA2sZqHTUVAmIGo= X-BSB-Auth: 1.66a9f7ae17fab844cc19.20160913010227BST.87mvjcr7jg.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:31349 Doc O'Leary writes: > For your reference, records indicate that > Ben Bacarisse wrote: > >> Being able to apply Math.max to a list is one reason it is variadic. > > Which has nothing to do with the *validity* of such functions under > certain input conditions. The whole question is whether or not the > results are *meaningful* for (some) multi-variable functions with > fewer arguments than are naturally expected. You've cut the context. I suspect that's deliberate. You were objecting to a rule which only makes sense about lists (well, arrays in ECMAScript) so it's important to explain why max might be called with zero arguments. You are unlikely to write Math.max() in your code, but you might apply max to an array. >> Given that, you don't want the partitioning a list to affect the result; > > I don’t give a damn what your internal implementation is. What? I'm not saying anything about the implementation. > I want a > result that doesn’t fabricate values that screw up future > calculations. > > If you can’t do that, you should indicate an error. Everything you do when you apply max to an empty array will be able to screw up some calculations. An exception needs to be handled and all the so-called 'fabricated' values -- null, undefined and NaN -- will be inappropriate in some situations. The point being made is that returning -Infinity is both useful and consistent, and not surprising to people used to other similar functions like 'some' and 'every'. >> I'm sure there *are* some inconsistencies, but max and min are, in this >> regard, consistent with every and some and Math.pow is unavoidably >> different from them all. That's not an inconsistency in the design. > > And what of the inconsistency in the root max() < min() comparison? > I consider *that* relationship to be more fundamental What relationship should they have? (This is a serious question -- I'm not sure what you aould have done had you been in charge.) > than how Math > was most conveniently implemented. I think you've misunderstood the case being made. It may well be convenient to implement it this way, but my interest is in making the function convenient to use. -- Ben.