Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27105
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Reach a digit of numerical value in array index. |
| Date | Sun, 22 Mar 2015 21:26:29 -0300 |
| Organization | Aioe.org NNTP Server |
| Lines | 54 |
| Message-ID | <menmjo$cs4$1@speranza.aioe.org> (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> <fbSfNlNPJLDVFwke@invalid.uk.co.demon.merlyn.invalid> <8127222.NEJAP2j12Q@PointedEars.de> |
| NNTP-Posting-Host | OsjKjz7AuNrX651V1sABXg.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.javascript:27105 |
Show key headers only | View raw
Thomas 'PointedEars' Lahn wrote:
> Dr J R Stockton wrote:
>
>> Consider and test
>>
>>
>> j = 3
>> n = 12345 ; X = (n % Math.pow(10, j)).toString().charAt(0)
>> n = 12045 ; Y = (n % Math.pow(10, j)).toString().charAt(0)
>> n = 00345 ; Z = (n % Math.pow(10, j)).toString().charAt(0)
>> Z = [X, Y, Z] ///// -> 3, 4, 2
>
> Right, you would need to pad the toString() result if the result of the “%”
> operation would be smaller than the 1-based index (j). I *did* test this
> approach before posting it – even though I also *did* point out *twice* that
> it is error-prone –, but not with such numbers.
>
<snip>
>
> Numeric integer literals with leading zero are parsed as octal in Mozilla
> JavaScript (and not a syntax error) when not in strict mode. No surprise
> here.
>
>> **TESTED** in current Firefox.
>
> Confirmed in Iceweasel 31.5.0 <snip>
>
Confirmed in Chrome 41 and IE 11 as well.
0345 // 229 [Z]
03458 // 3458
077 // 63
078 // 78
01234567 // 342391
012345678 // 12345678
0123456789 // 123456789
[1] <http://ecma-international.org/ecma-262/5.1/#sec-7.8.3>
<http://ecma-international.org/ecma-262/5.1/#sec-B.1.1>
A conforming implementation, when processing strict mode code (#10.1.1),
must not extend the syntax of NumericLiteral to include
OctalIntegerLiteral as described in B.1.1.
In ECMAScript 6, octal number syntax uses a leading zero followed by a
lowercase or uppercase Latin letter "O" (0o or 0O).
--
Joao Rodrigues
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