Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: How would you prepare for javascripting interview? Date: Tue, 06 Sep 2016 19:40:25 +0200 Organization: PointedEars Software (PES) Lines: 44 Message-ID: <5196662.lOV4Wx5bFT@PointedEars.de> References: <50e38667-93da-4c5d-bc02-a78394f0ca3b@googlegroups.com> <1875389.irdbgypaU6@PointedEars.de> <87h99vz2lp.fsf@bsb.me.uk> <2puqsbta8crtl2lthb1c63dpkqohbgtq0m@4ax.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1473183627 28320 eJwFwYERgDAIA8CVaEmCjsNF2H8E/5k6ckEUuNxuZ8m5ywTwFop3PUPsOLLpz3ZEPX1C9wcm7BFY (6 Sep 2016 17:40:27 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 6 Sep 2016 17:40:27 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Lock: sha1:iLB1hLkYGhm77Cgsis/vBEc99do= X-User-ID: eJwNysEBwCAIA8CVQEyUcUSa/Ueo7zsEnXdNghOCaAJjNANutJNZjfjGlqVvDGixzT/lqxVP6mKL2XXugx8o3RUF X-NNTP-Posting-Host: eJwFwQEBwDAIAzBL60rh2AGOfwlLRId3mMtNq7Wd4gVLPqzD+Bt1dycLGETayT7c+EKU1QMfNxDJ Xref: csiph.com comp.lang.javascript:31256 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.