Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20424
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <2496880.a6ciHIckR8@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Tue, 25 Jun 2013 03:06:36 +0200 |
| User-Agent | KNode/4.10.4 |
| Content-Transfer-Encoding | 7Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: Looping holding old copy of array |
| Newsgroups | comp.lang.javascript |
| References | <6870a10e-ea81-40d5-91f8-ce425152e543@googlegroups.com> <XnsA1E963239D075eejj99@194.109.133.133> <f9fdda94-c977-42f5-af79-89a5d2155a85@googlegroups.com> |
| MIME-Version | 1.0 |
| Lines | 110 |
| NNTP-Posting-Date | 25 Jun 2013 03:06:43 CEST |
| NNTP-Posting-Host | 4915e16f.newsspool3.arcor-online.net |
| X-Trace | DXC=\?[_Q5=TjT`f1oJaJ0@dmgMcF=Q^Z^V3h4Fo<]lROoRa8kF<OcfhCOk?F<P;FJ26_bDZm8W4\YJNlb@mF9jNikdeBoKGPB=12AgeRb8]PAfTbk |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:20424 |
Show key headers only | View raw
Michael Haufe (TNO) wrote:
> On Monday, June 24, 2013 2:44:44 AM UTC-5, Evertjan. wrote:
>> jonas.thornvall wrote on 24 jun 2013 in comp.lang.javascript:
>>
>>
>>
>> > I have a looping algorithm that must use least amount of work.
>>
>> > I am working on an array and that use a counter for loop behaviour
>>
>> > (loop in a loop).
>>
>> >
>>
>> > However when loops finished, i need a copy of the array containing not
>>
>> > the last item but the item before the last.
>>
>> >
>>
>> > Basicly i have two while loops
>>
>> > while x>y
>>
>> > while z>t
>>
>> > change Aarray
>>
>> >
>>
>> > I want the content saved of the pre Aarray before loopend
>>
>> >
>>
>> >
>>
>> > Here is my thought either i use
>>
>> >
>>
>> > while x>y
>>
>> > newArray = Aarray.slice();
>>
>> > while z>t
>>
>> > change Aarray
>>
>> >
>>
>> > or i use
>>
>> >
>>
>> >
>>
>> > while x>y
>>
>> > for(i=0;i<Aarray.length;i++){
Safer and more efficient:
for (var i = 0, len = Aarray.length; i < len; ++i)
{
Using identifiers starting with capital letters for variables that do not
hold references to constructors is unwise.
>> > newCopy[i] = Aarray[i];
>>
>> > }
>>
>> > while z>t
>>
>> > change Aarray
>>
>> >
>>
>> > I do not like to make a copy everytime, but is there away around it?
>>
>> > Which of the two suggested methods is faster?
>
> [...]
>
> I can't see the original message for some reason...
>
> But at any rate, I'd suggest using myArray.map(...)
>
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map>
Unwise here for several reasons. Array.prototype.slice() is the most
efficient method to make a shallow copy of an encapsulated array structure.
It can also be used to make a shallow copy of only a part of the array
structure, hence its name.
I find the original question to be too unclearly worded to suggest a correct
alternative. On top of that it is hardly readable thanks to lack of Pretty
Printing, and to borken Google Groups; obviously it gets worse with any
followup to it posted via Google Groups (full quote intended here to show
that).
Do not use Google Groups for posting (unless you know how to work around its
bugs, assuming that possibility still exists).
--
PointedEars
Twitter: @PointedEars2
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
Looping holding old copy of array jonas.thornvall@gmail.com - 2013-06-23 22:50 -0700
Re: Looping holding old copy of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-24 09:44 +0200
Re: Looping holding old copy of array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-06-24 16:45 -0700
Re: Looping holding old copy of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-25 03:06 +0200
Re: Looping holding old copy of array Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-06-25 21:58 +0200
Re: Looping holding old copy of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-25 23:03 +0200
Re: Looping holding old copy of array JJ <duh@nah.meh> - 2013-06-24 15:19 +0700
Re: Looping holding old copy of array jonas.thornvall@gmail.com - 2013-06-24 03:38 -0700
Re: Looping holding old copy of array JJ <duh@nah.meh> - 2013-06-25 10:52 +0700
csiph-web