Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27778
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Merge indexes.. |
| Date | 2015-05-20 15:52 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1741822.HK0jiq3ONr@PointedEars.de> (permalink) |
| References | <143762f6-417f-4f3f-82d5-272939e581d9@googlegroups.com> <e1b4d9fe-2a97-493f-8d32-9995dc969ac2@googlegroups.com> <87h9r7o7gw.fsf@bsb.me.uk> <lh2pla9u4416cnr1pa98d169rpv9g9csdd@4ax.com> <3972519.ny49QEeFJO@PointedEars.de> |
Thomas 'PointedEars' Lahn wrote:
> John Harris wrote:
>> […] Ben Bacarisse […] wrote:
>>> jonas.thornvall@gmail.com writes:
>>>> <script>
>>>> function merge(){
>>>> for (i=0;i<myArr.length;i++){
>>>> myInt=(myArr[i]*x)+myInt;
>>>> x=x*10;
>>>> }
>>>> }
>>>> myArr =[7,9,8]
>>>> myInt=0;
>>>> x=1;
>>>> merge();
>>>> document.write(myInt);
>>>> </script>
>>>
>>>Don't make you code worse by adding yet more function that communicate
>>>via globals. This operation is a self-contained function of the array.
>>>Pass the array as a parameter and return the result from the function.
>>
>> Even better, pass the base, x, as a parameter as well.
>
> And for bases from 2 to 36, just return parseInt(a.join(""), base), with
> both “a” and “base” being formal parameters of merge(). No need to
> reinvent Wheel 0.1:
>
> <http://ecma-international.org/ecma-262/5.1/#sec-15.1.2.2>
This optimization works only if the elements of the array are the digits in
the other base (e.g., strings of length 1 if necessary), not the decimal
digit-values. So it definitely works only for bases 2 to 10 where the
string representation of each digit always has length 1 (no matter whether
it is stored as a string or a number).
--
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
Merge indexes.. jonas.thornvall@gmail.com - 2015-05-19 23:59 -0700
Re: Merge indexes.. jonas.thornvall@gmail.com - 2015-05-20 01:20 -0700
Re: Merge indexes.. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-20 11:42 +0100
Re: Merge indexes.. jonas.thornvall@gmail.com - 2015-05-20 06:16 -0700
Re: Merge indexes.. John Harris <niam@jghnorth.org.uk.invalid> - 2015-05-20 14:21 +0100
Re: Merge indexes.. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 15:32 +0200
Re: Merge indexes.. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 15:52 +0200
Re: Merge indexes.. jonas.thornvall@gmail.com - 2015-05-20 08:23 -0700
Re: Merge indexes.. jonas.thornvall@gmail.com - 2015-05-21 05:51 -0700
Re: Merge indexes.. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-21 15:44 +0200
Re: Merge indexes.. jonas.thornvall@gmail.com - 2015-05-21 07:24 -0700
Re: Merge indexes.. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 15:52 +0100
Re: Merge indexes.. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 09:40 +0200
Re: Merge indexes.. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-23 11:54 +0200
Re: Merge indexes.. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-21 22:49 +0200
Re: Merge indexes.. Andrew Poulos <ap_prog@hotmail.com> - 2015-05-20 20:55 +1000
Re: Merge indexes.. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-20 04:50 -0700
Re: Merge indexes.. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 14:32 +0200
Re: Merge indexes.. "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-20 15:12 +0200
csiph-web