Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Bignumb addition function, suggestion improvements. Date: Sat, 14 Mar 2015 20:56:08 +0100 Organization: PointedEars Software (PES) Lines: 38 Message-ID: <1870601.SULIsds41C@PointedEars.de> References: <87fv97u25x.fsf@bsb.me.uk> <531f97ee-89e2-49a6-b9a8-4b11102e998c@googlegroups.com> <878uezpdv6.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1426363063 1198 eJwFwQEBwDAIAzBLlFGYnQGvfwlPeBI5FckMigK1zObMcVnxefau2o03ugB8a9DeiEcP/SE8ER4= (14 Mar 2015 19:57:43 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sat, 14 Mar 2015 19:57:43 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CX7IRCz1GE/09Y4ptghdFpPj7SVDS9dLHqrtvB0LfwpPpQ8GUopiabCdNr1/HdCbWd9wNJLxUk Cancel-Lock: sha1:idW14lHLVpRdtXWqyem+tz63CEA= X-NNTP-Posting-Host: eJwNyskRwEAIA7CWuAyz5QCD+y8h0Vvw1NyKRAYILuPqdl0CMi005htUahuGj/7nsOsWZcV8LIsRhQ== Xref: csiph.com comp.lang.javascript:27037 Ben Bacarisse wrote: > jonas.thornvall@gmail.com writes: >> Den lördag 14 mars 2015 kl. 14:41:35 UTC+1 skrev Ben Bacarisse: >>> String.prototype.digitValueAt = function (pos) { >>> var d = this.charCodeAt(pos); >>> return isNaN(d) ? 0 : d - 48; >>> } >> >> I do not get ? 0 : d - 48; > > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator > > The 48 is "0".charCodeAt(0) which would be have been more > self-documenting. Apropos: s.digitValueAt(pos) where s is a String, would be equivalent to +s.charAt(pos) || 0 or even +s[pos] || 0 in JavaScript 1.5+ and more recent implementations of ECMAScript. (“…[…]” is _not_ an operation.) -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.