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: Mon, 05 Sep 2016 20:12:42 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: <87zinmxis5.fsf@bsb.me.uk> References: <50e38667-93da-4c5d-bc02-a78394f0ca3b@googlegroups.com> <1875389.irdbgypaU6@PointedEars.de> <87h99vz2lp.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="20562"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xYjMR+M5mW9RbbRqsUXqi17W3FDlksWw=" Cancel-Lock: sha1:LHG5xv9/MQZO30tURd2CArNXQHA= sha1:o6ZX7IHRx2/a7zbsZgPdNwd3k0c= X-BSB-Auth: 1.f897d701364a96c4ace7.20160905201242BST.87zinmxis5.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:31242 Doc O'Leary writes: > For your reference, records indicate that > Ben Bacarisse 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.