Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27776
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!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: Merge indexes.. |
| Date | Wed, 20 May 2015 15:32:47 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 39 |
| Message-ID | <3972519.ny49QEeFJO@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> |
| 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 1432128928 10393 eJwNyckBwDAIA7CVaMEmjFOu/UdI9RWUD8uNoGGxLlmYhswYIF4nIX9+iOmW0HiRh5pYmqVeGEsQqw== (20 May 2015 13:35:28 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Wed, 20 May 2015 13:35:28 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwFwYEBgDAIA7CXGKytnCMI/59gguBh6xK8WOzCRbPpUy5N3O6emnUDfCYxalgxvgodS6TIyEQ8/un1H1JuFOA= |
| Cancel-Lock | sha1:82z9BXZ8WeeYd3Y7jVGQz2kGHQ0= |
| X-NNTP-Posting-Host | eJwNyrEBwDAIA7CXSmNsOIc08P8JzaJJvmj8BDrh41PSzoCFYdjNtL2Aky9STsW9T9fVo+eofgcKEJ0= |
| Xref | csiph.com comp.lang.javascript:27776 |
Show key headers only | View raw
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>
Finally, make merge() the valueOf() method of your own object type, so that
“a” and maybe even “base” can be replaced by references to properties of the
instance.
--
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