Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27077
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Reach a digit of numerical value in array index. |
| Date | Thu, 19 Mar 2015 16:13:08 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 29 |
| Message-ID | <4183666.fxmPkqLfvv@PointedEars.de> (permalink) |
| References | <7bb55099-4d9b-46e0-b4b7-3785304be4f4@googlegroups.com> <medgv0$gjb$1@dont-email.me> <49b891b6-283a-45ed-beec-3cdc19983595@googlegroups.com> <9k5lgatqlm6esvojkhsntbcdpk58ma2gka@4ax.com> <2641901.31sAzN5gEV@PointedEars.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1426778116 3821 eJwFwYEBACAEBMCVKP8yDsr+I3SHTWW7ETQMxliNU6BjUkL6FNcOlRmNeu9p1pJ7OxLw6g8b8BGO (19 Mar 2015 15:15:16 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Thu, 19 Mar 2015 15:15:16 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNwQkBgAAIA8BKU946wKB/BL0z8ccn1M3Vzg7RVDG54mmCUpJFzE0AbFXdvsLPN3d2rBrMNzJsKPEBbYUWOA== |
| Cancel-Lock | sha1:VLfu9eA81pf+4/WaQh3xyDCH9iI= |
| X-NNTP-Posting-Host | eJwFwYEBwCAIA7CXFGjrzgEH/59gAufmVRAMDOaOuA1MD6AgVZudzvzi1xr1obDQ18xRyQcQ3RCq |
| Xref | csiph.com comp.lang.javascript:27077 |
Show key headers only | View raw
Thomas 'PointedEars' Lahn wrote: > […] there are (at least) three ways to retrieve the decimal > digit from a Number value without a "temporary variable"; just error-prone > and not very efficient ones (so kids, don’t do this at home): > > a) n.toString().charAt(i) > b) n.toString().slice(-j, -j + 1) > c) (n % Math.pow(10, j)).toString().charAt(0) > > where “n” is (a variable storing) the Number value (preferably a numeric > integer), “i” is (a variable storing) the 0-based index of the digit > counted from the left, and “j” is (a variable storing) the 1-based index > of the digit counted from the right. > > I do not think I need to explain why these approaches are not very > efficient. They are also error-prone because of limited precision of the > IEEE 754 double-precision floating-point format as such, and of the string > representation of its values in ECMAScript. For recreation, here is another one: d) Math.floor((n % Math.pow(10, j)) / Math.pow(10, j - 1)) -- 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.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-17 14:15 -0700
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-17 14:34 -0700
Re: Reach a digit of numerical value in array index. JJ <jj4public@vfemail.net> - 2015-03-18 13:38 +0700
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-18 06:57 -0700
Re: Reach a digit of numerical value in array index. Norman Peelman <npeelman@cfl.rr.com> - 2015-03-18 23:49 -0400
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-19 01:16 -0700
Re: Reach a digit of numerical value in array index. John Harris <niam@jghnorth.org.uk.invalid> - 2015-03-19 09:28 +0000
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-19 05:00 -0700
Re: Reach a digit of numerical value in array index. John Harris <niam@jghnorth.org.uk.invalid> - 2015-03-19 16:23 +0000
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-19 10:43 -0700
Re: Reach a digit of numerical value in array index. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-03-19 19:51 +0100
Re: Reach a digit of numerical value in array index. John Harris <niam@jghnorth.org.uk.invalid> - 2015-03-22 11:20 +0000
Re: Reach a digit of numerical value in array index. jonas.thornvall@gmail.com - 2015-03-22 08:18 -0700
Re: Reach a digit of numerical value in array index. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-19 15:59 +0100
Re: Reach a digit of numerical value in array index. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-19 16:13 +0100
Re: Reach a digit of numerical value in array index. Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> - 2015-03-20 23:50 +0000
Re: Reach a digit of numerical value in array index. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-22 16:29 +0100
Re: Reach a digit of numerical value in array index. Scott Sauyet <scott@sauyet.com> - 2015-03-22 17:36 -0400
Re: Reach a digit of numerical value in array index. Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-03-22 21:26 -0300
Re: Reach a digit of numerical value in array index. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-23 05:54 +0100
csiph-web