Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27063 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2015-03-17 14:15 -0700 |
| Last post | 2015-03-23 05:54 +0100 |
| Articles | 20 — 9 participants |
Back to article view | Back to comp.lang.javascript
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
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-17 14:15 -0700 |
| Subject | Reach a digit of numerical value in array index. |
| Message-ID | <7bb55099-4d9b-46e0-b4b7-3785304be4f4@googlegroups.com> |
var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. i=0; result[i]=compute[0][i]+compute[1][i]; //Well this does not work Is it even possible without saving the index? Is this really necessary? i=0; intA=compute[0]; intB=compute[1] result[i]=intA+intB;
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-17 14:34 -0700 |
| Message-ID | <31966623-479e-4bc9-bf79-f9a745b498a0@googlegroups.com> |
| In reply to | #27063 |
Den tisdag 17 mars 2015 kl. 22:16:04 UTC+1 skrev jonas.t...@gmail.com: > var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. > > i=0; > result[i]=compute[0][i]+compute[1][i]; //Well this does not work > > Is it even possible without saving the index? > Is this really necessary? > i=0; > intA=compute[0]; > intB=compute[1] > result[i]=intA+intB; Ok i am tired, there is no way to reach the index witin an integer in javascript? It seem it was very stupid of me converting the strings to numbers in the first place. But really?
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2015-03-18 13:38 +0700 |
| Message-ID | <9eqsadinclv2$.pcq50b0xm3hy.dlg@40tude.net> |
| In reply to | #27064 |
On Tue, 17 Mar 2015 14:34:56 -0700 (PDT), jonas.thornvall@gmail.com wrote: > Den tisdag 17 mars 2015 kl. 22:16:04 UTC+1 skrev jonas.t...@gmail.com: >> var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. >> >> i=0; >> result[i]=compute[0][i]+compute[1][i]; //Well this does not work From what I can see, it doesn't work because "result" is not yet defined. >> Is it even possible without saving the index? >> Is this really necessary? >> i=0; >> intA=compute[0]; >> intB=compute[1] >> result[i]=intA+intB; Yes: result[0]=intA+intB; > Ok i am tired, there is no way to reach the index witin an integer in javascript? If you meant to get the index of a specific value of an array, use this: var valueToSearch = 3; var valueIndex = myArray.indexOf(valueToSearch); > It seem it was very stupid of me converting the strings to numbers in the first place. > > But really? What string?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-18 06:57 -0700 |
| Message-ID | <e63d53df-2915-48e1-ba67-729180981e1e@googlegroups.com> |
| In reply to | #27065 |
Den onsdag 18 mars 2015 kl. 07:38:29 UTC+1 skrev JJ: > On Tue, 17 Mar 2015 14:34:56 -0700 (PDT), jonas.thornvall@gmail.com wrote: > > Den tisdag 17 mars 2015 kl. 22:16:04 UTC+1 skrev jonas.t...@gmail.com: > >> var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. > >> > >> i=0; > >> result[i]=compute[0][i]+compute[1][i]; //Well this does not work > > From what I can see, it doesn't work because "result" is not yet defined. No it really does not work, compute is an array of integers, and you can not treat it as a two dimensional array to reach a digit. > >> Is it even possible without saving the index? > >> Is this really necessary? > >> i=0; > >> intA=compute[0]; > >> intB=compute[1] > >> result[i]=intA+intB; > > Yes: result[0]=intA+intB; > > > Ok i am tired, there is no way to reach the index witin an integer in javascript? > > If you meant to get the index of a specific value of an array, use this: > > var valueToSearch = 3; > var valueIndex = myArray.indexOf(valueToSearch); I think that the result not an integer from indexOf, and than it does not make sense to use parseInt again. > > It seem it was very stupid of me converting the strings to numbers in the first place. > > > > But really? > > What string?
[toc] | [prev] | [next] | [standalone]
| From | Norman Peelman <npeelman@cfl.rr.com> |
|---|---|
| Date | 2015-03-18 23:49 -0400 |
| Message-ID | <medgv0$gjb$1@dont-email.me> |
| In reply to | #27063 |
On 03/17/2015 05:15 PM, jonas.thornvall@gmail.com wrote: > var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. > > i=0; > result[i]=compute[0][i]+compute[1][i]; //Well this does not work > > Is it even possible without saving the index? > Is this really necessary? > i=0; > intA=compute[0]; > intB=compute[1] > result[i]=intA+intB; > You aren't dealing with strings here, it doesn't work that way. -- Norman Registered Linux user #461062 AMD64X2 6400+ Ubuntu 10.04 64bit
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-19 01:16 -0700 |
| Message-ID | <49b891b6-283a-45ed-beec-3cdc19983595@googlegroups.com> |
| In reply to | #27070 |
Den torsdag 19 mars 2015 kl. 04:49:49 UTC+1 skrev Norman Peelman: > On 03/17/2015 05:15 PM, jonas.thornvall@gmail.com wrote: > > var Compute=[] is an array/stack holding integer values now i want to add individual digits store them in result. > > > > i=0; > > result[i]=compute[0][i]+compute[1][i]; //Well this does not work > > > > Is it even possible without saving the index? > > Is this really necessary? > > i=0; > > intA=compute[0]; > > intB=compute[1] > > result[i]=intA+intB; > > > > You aren't dealing with strings here, it doesn't work that way. > > > -- > Norman > Registered Linux user #461062 > AMD64X2 6400+ Ubuntu 10.04 64bit Well i know howto do it, but its insane, i questioning why one can not read/reach the digit place of a number stored in an array, without going via temp variables. There should be a way reading them straight out of the index.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2015-03-19 09:28 +0000 |
| Message-ID | <9k5lgatqlm6esvojkhsntbcdpk58ma2gka@4ax.com> |
| In reply to | #27071 |
On Thu, 19 Mar 2015 01:16:40 -0700 (PDT), jonas.thornvall@gmail.com wrote: <snip> >Well i know howto do it, but its insane, >i questioning why one can not read/reach the digit place >of a number stored in an array, without going via temp variables. >There should be a way reading them straight out of the index. Why should there be? Remember that what's stored are binary numbers. Do you really want to fetch a binary digit? John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-19 05:00 -0700 |
| Message-ID | <bb9a6a93-b999-47fb-8d2b-f7475783f2ae@googlegroups.com> |
| In reply to | #27073 |
Den torsdag 19 mars 2015 kl. 10:28:12 UTC+1 skrev John Harris: > On Thu, 19 Mar 2015 01:16:40 -0700 (PDT), jonas.thornvall@gmail.com > wrote: > > > <snip> > >Well i know howto do it, but its insane, > >i questioning why one can not read/reach the digit place > >of a number stored in an array, without going via temp variables. > >There should be a way reading them straight out of the index. > > Why should there be? > > Remember that what's stored are binary numbers. Do you really want to > fetch a binary digit? > > John Yeah why not i guess that make the adder faster, doing bit addition rather than byte. Well it may end up being the same work but that is not the point.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2015-03-19 16:23 +0000 |
| Message-ID | <tutlgalnnf3qfn6qlf1qbqnjldkblrhtsa@4ax.com> |
| In reply to | #27075 |
On Thu, 19 Mar 2015 05:00:36 -0700 (PDT), jonas.thornvall@gmail.com wrote: >Den torsdag 19 mars 2015 kl. 10:28:12 UTC+1 skrev John Harris: >> On Thu, 19 Mar 2015 01:16:40 -0700 (PDT), jonas.thornvall@gmail.com >> wrote: >> >> >> <snip> >> >Well i know howto do it, but its insane, >> >i questioning why one can not read/reach the digit place >> >of a number stored in an array, without going via temp variables. >> >There should be a way reading them straight out of the index. >> >> Why should there be? >> >> Remember that what's stored are binary numbers. Do you really want to >> fetch a binary digit? >> >> John > >Yeah why not i guess that make the adder faster, doing bit addition rather than byte. Well it may end up being the same work but that is not the point. On second thoughts I haven't the faintest idea what you are saying and what your question is. Are you talking about an array of ECMAScript numbers, an array of strings holding a representation of a big number, or an array of arrays of ECMAScript numbers holding a representation of a big number? John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-19 10:43 -0700 |
| Message-ID | <a1457394-de89-48fe-bc16-d04ab64486ba@googlegroups.com> |
| In reply to | #27079 |
Den torsdag 19 mars 2015 kl. 17:23:18 UTC+1 skrev John Harris: > On Thu, 19 Mar 2015 05:00:36 -0700 (PDT), jonas.thornvall@gmail.com > wrote: > > >Den torsdag 19 mars 2015 kl. 10:28:12 UTC+1 skrev John Harris: > >> On Thu, 19 Mar 2015 01:16:40 -0700 (PDT), jonas.thornvall@gmail.com > >> wrote: > >> > >> > >> <snip> > >> >Well i know howto do it, but its insane, > >> >i questioning why one can not read/reach the digit place > >> >of a number stored in an array, without going via temp variables. > >> >There should be a way reading them straight out of the index. > >> > >> Why should there be? > >> > >> Remember that what's stored are binary numbers. Do you really want to > >> fetch a binary digit? > >> > >> John > > > >Yeah why not i guess that make the adder faster, doing bit addition rather than byte. Well it may end up being the same work but that is not the point. > > On second thoughts I haven't the faintest idea what you are saying and > what your question is. > > Are you talking about an array of ECMAScript numbers, an array of > strings holding a representation of a big number, or an array of > arrays of ECMAScript numbers holding a representation of a big number? > > > John It did hold integers, but i changed the code so it is a none issue now, i just remarked on that there is no simple way to read out a digit of an integer stored at an index within an array. That is all.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-03-19 19:51 +0100 |
| Message-ID | <XnsA462C9F81AB8Beejj99@194.109.6.166> |
| In reply to | #27081 |
jonas.thornvall@gmail.com wrote on 19 mrt 2015 in comp.lang.javascript: > It did hold integers, but i changed the code so it is a none issue now, This is usenet, you don't decide whether something becomes a "non-issue", when you change something. btw, what is a "none issue"? Or is that a non-issue too? > i just remarked on that there is no simple way to read out a digit of an > integer stored at an index within an array. Nonsense. It is impossible to determine, because, independent of where the integer is stored, it is stored as a floating point binary variable, so "digit" has no fixed meaning here. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2015-03-22 11:20 +0000 |
| Message-ID | <jb9tgat817mlcmjk4usitd3cch5kkid004@4ax.com> |
| In reply to | #27081 |
On Thu, 19 Mar 2015 10:43:58 -0700 (PDT), jonas.thornvall@gmail.com wrote: >Den torsdag 19 mars 2015 kl. 17:23:18 UTC+1 skrev John Harris: <snip> >> On second thoughts I haven't the faintest idea what you are saying and >> what your question is. >> >> Are you talking about an array of ECMAScript numbers, an array of >> strings holding a representation of a big number, or an array of >> arrays of ECMAScript numbers holding a representation of a big number? <snip> >i just remarked on that there is no simple way to read out a digit of an >integer stored at an index within an array. So you call this function and it returns 7 if it's currently a decimal integer, E if a hexadecimal integer, 2 if a ternary integer, 0 if it's a binary integer. How can you say it's a 'simple way' ? John
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-22 08:18 -0700 |
| Message-ID | <6409c5b6-c4c8-47bb-be7d-1a425348d509@googlegroups.com> |
| In reply to | #27099 |
Den söndag 22 mars 2015 kl. 12:20:52 UTC+1 skrev John Harris: > On Thu, 19 Mar 2015 10:43:58 -0700 (PDT), jonas.thornvall@gmail.com > wrote: > > >Den torsdag 19 mars 2015 kl. 17:23:18 UTC+1 skrev John Harris: > > <snip> > >> On second thoughts I haven't the faintest idea what you are saying and > >> what your question is. > >> > >> Are you talking about an array of ECMAScript numbers, an array of > >> strings holding a representation of a big number, or an array of > >> arrays of ECMAScript numbers holding a representation of a big number? > <snip> > > >i just remarked on that there is no simple way to read out a digit of an > >integer stored at an index within an array. > > So you call this function and it returns 7 if it's currently a decimal > integer, E if a hexadecimal integer, 2 if a ternary integer, 0 if it's > a binary integer. > > How can you say it's a 'simple way' ? > > John Well you know as well as i that ECMA script is full of functions doing type transformations. I just noticed there is none that work on index in an array.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-03-19 15:59 +0100 |
| Message-ID | <2641901.31sAzN5gEV@PointedEars.de> |
| In reply to | #27073 |
John Harris wrote: > […] jonas.thornvall@gmail.com wrote: >> Well i know howto do it, but its insane, >> i questioning why one can not read/reach the digit place >> of a number stored in an array, without going via temp variables. >> There should be a way reading them straight out of the index. > Why should there be? > > Remember that what's stored are binary numbers. Do you really want to > fetch a binary digit? ACK. That said, 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. -- 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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-03-19 16:13 +0100 |
| Message-ID | <4183666.fxmPkqLfvv@PointedEars.de> |
| In reply to | #27076 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2015-03-20 23:50 +0000 |
| Message-ID | <fbSfNlNPJLDVFwke@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #27076 |
In comp.lang.javascript message <2641901.31sAzN5gEV@PointedEars.de>,
Thu, 19 Mar 2015 15:59:25, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:
>ACK. That said, 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.
Efficiency may not be important, but correctness usually is.
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
in which Z is present for amazement/amusement only.
**TESTED** in current Firefox.
--
(c) John Stockton, nr London, UK. For Mail, see Home Page. Turnpike, WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
DOS/Win/UNIX now 2.0.6; see my <http://www.merlyn.demon.co.uk/pc-links.htm>.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-03-22 16:29 +0100 |
| Message-ID | <8127222.NEJAP2j12Q@PointedEars.de> |
| In reply to | #27093 |
Dr J R Stockton wrote: > [A long time ago, in a galaxy far, far away] Thomas 'PointedEars' Lahn > [posted this story: ] When will you stop posting those attribution novels? > 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. > in which Z is present for amazement/amusement only. 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 (“current” is not a sensible designation, especially not with rapid releases). -- 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.
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Date | 2015-03-22 17:36 -0400 |
| Message-ID | <MPG.2f78fffe94b8ba41989680@news.eternal-september.org> |
| In reply to | #27101 |
Thomas 'PointedEars' Lahn wrote: > Dr J R Stockton wrote: > > > [A long time ago, in a galaxy far, far away] Thomas 'PointedEars' Lahn > > [posted this story: ] > > When will you stop posting those attribution novels? Dr. Stockton has long made it clear that he doesn't agree with you on this issue. Is there a reason to continue to pursue it? Moreover, his attribution took 148 characters and three newlines. Your rebuke took 147 characters and four newlines. How does that help? And now I'm adding to it! :-( -- Scott
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2015-03-22 21:26 -0300 |
| Message-ID | <menmjo$cs4$1@speranza.aioe.org> |
| In reply to | #27101 |
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
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-03-23 05:54 +0100 |
| Message-ID | <1776549.81HIkUI3fx@PointedEars.de> |
| In reply to | #27105 |
Joao Rodrigues wrote: > [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). ACK, thx. You should use quotation marks or the “|” prefix to make clear which statements are quotations from references and which are your own. Also, ECMAScript Edition 6 is still a working draft. References to it should reflect that fact. -- 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web