Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Reach a digit of numerical value in array index. Date: Sun, 22 Mar 2015 16:29:03 +0100 Organization: PointedEars Software (PES) Lines: 37 Message-ID: <8127222.NEJAP2j12Q@PointedEars.de> References: <7bb55099-4d9b-46e0-b4b7-3785304be4f4@googlegroups.com> <49b891b6-283a-45ed-beec-3cdc19983595@googlegroups.com> <9k5lgatqlm6esvojkhsntbcdpk58ma2gka@4ax.com> <2641901.31sAzN5gEV@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1427038243 14851 eJwFwYEBwCAIA7CXhNE6zpnF/n/CEjwMahfBguEB3HxHrWz4HsldQi4kejF82en65qjC+QMoTRF2 (22 Mar 2015 15:30:43 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 22 Mar 2015 15:30:43 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwVxccRBEEIA8CUMBIw4TCG/EPYu+pH00PjJIIBzl+84W4p6g3f6VKgdGG1T8moWdtbZxS/5+bWO2e5vSQaH04pFY4= Cancel-Lock: sha1:yg3M5VNi95+TZCNlcDXvFFY+Kno= X-NNTP-Posting-Host: eJwNycERACEIA8CWlAA5ygGd9F+Ct98N5M5Dz0gPhXJsRjj9FZ1/0vaAXOaXgrpgci5cq4bmARCSEKI= Xref: csiph.com comp.lang.javascript:27101 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.