Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27774
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2015-05-20 06:16 -0700 |
| References | <143762f6-417f-4f3f-82d5-272939e581d9@googlegroups.com> <e1b4d9fe-2a97-493f-8d32-9995dc969ac2@googlegroups.com> <87h9r7o7gw.fsf@bsb.me.uk> |
| Message-ID | <20169d03-e566-4748-ada3-40bdfb572916@googlegroups.com> (permalink) |
| Subject | Re: Merge indexes.. |
| From | jonas.thornvall@gmail.com |
Den onsdag 20 maj 2015 kl. 12:43:00 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > Den onsdag 20 maj 2015 kl. 08:59:15 UTC+2 skrev jonas.t...@gmail.com:
> >> I need to merge integers at indexes within an array into an integer?
> >> [7,9,8] = 798
> >>
> >> No join i need an integer value.
> >>
> >> How?
> >
> > Sorry i was thinking wrong should be 897, i have one way todo it. But
> > i was thinking it should be possible to do with just concatenations
> > rather than arithmetic?
>
> That's because you are still not clear about the distinction between a
> number and its representation. If you have Number values (that's an
> ECMAScrip type) then arithmetic is the correct way to produce new
> numbers like this.
>
> > <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.
>
> --
> Ben.
It was actually just a draw here is the one in script.
"I got it to work see next post, do both arithmetic on unsigned pairs, *arithmetic and conversion in anybase* see new post.
Now i can change the digit add within conversion to either a division or a search, have not decided which. It should make a big difference converting very big numbers.
/* MERGE THE INTEGER INDEXES OF AN ARRAY INTO ONE INTEGER */
function mergeArr(myArr)
{
myInt = 0;
x = 1;
for (i = 0; i < myArr.length; i ++ )
{
myInt = (myArr[i] * x) + myInt;
x = x * 10;
}
return myInt;
}
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