Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rolf Niepraschk Newsgroups: comp.lang.javascript Subject: Re: Iterating through an array (special syntax) Date: Fri, 20 Oct 2017 07:55:23 +0200 Lines: 40 Message-ID: References: <7f583c52-91a8-4773-a2cb-bc8534a1ad78@googlegroups.com> <22557651-daf7-4252-b3a4-c9df083be85c@googlegroups.com> <526590a8-1952-4da6-a8cd-525eef79df6f@googlegroups.com> <1876626.bB369e8A3T@PointedEars.de> Reply-To: Rolf.Niepraschk@gmx.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 0m+dwkSsnqBeh0XABb+ZQQH+GZFL1E6lLrf0ZlD37f/CL1BlUH Cancel-Lock: sha1:xosGskDbt1XCMluaOGZvYyaO6yI= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 In-Reply-To: <1876626.bB369e8A3T@PointedEars.de> Content-Language: en-US Xref: csiph.com comp.lang.javascript:34150 Am 19.10.2017 um 21:53 schrieb Thomas 'PointedEars' Lahn: ... > > Unless oldItems.length changes, > > for (var i=0, len = oldItems.length; i < len; i++) { > > is more efficient. Are you sure? I see no much differences (at least with nodejs 8): #================================================= #!/usr/bin/env node var arr = []; for(var i=0; i<5E7; i++) arr.push(i); var x, start; start = new Date().getTime(); for (var i=0; i >> fn_each(oldItems[i], newItems[i]); >> } > > This loop is pointlessly inefficient in any case. You are already using > Array.prototype.map(), thereby iterating through the array, so you can > either output or accumulate the old and new value *in the callback*. Ok. I will think about your Promise solution. Thanks for your explanation. ...Rolf