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> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. 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 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> > 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(...) > > 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.