Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22360
| Message-ID | <1693047.RCSKjYtSyA@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-12-17 21:42 +0100 |
| Subject | Re: Date Conversion ? |
| Newsgroups | comp.lang.javascript |
| References | <bh9en6Foh76U1@mid.individual.net> <1l7578dngtzld$.19qzw1e0gy93t$.dlg@40tude.net> <l8o67q$tli$1@dont-email.me> <1744237.gKV8rdnPMv@PointedEars.de> <l8qb46$me$1@speranza.aioe.org> |
Joao Rodrigues wrote:
> On 17/12/2013 12:12, Thomas 'PointedEars' Lahn wrote:
>> One can also access the first and last element of a sorted array:
>>
>> var sortedCopy = arr.slice().sort(function (a, b) { return a - b; });
>> var low = sortedCopy[0];
>> var high = sortedCopy[sortedCopy.length - 1];
>>
>> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.11>
>
> or
>
> var low = sortedCopy.shift();
> var high = sortedCopy.pop();
If you do not need the original copy later. Because the property accessor
does not modify the array like these two methods do.
>> Finally, all implementations of ECMAScript Ed. 5 – not just JavaScript
>> anymore – provide Array.prototype.reduce(), as mentioned by Björn:
>>
>> var low = arr.reduce(
>> function (accumulator, e, i, a) {
>> if (е < accumulator)
>> {
>> return e;
>> }
>>
>> return accumulator;
>> },
>> arr[0]);
>>
>> <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.21>
>
> 'accumulator' is a bad name, as you are not accumulating anything in
> that function.
The name fits. An accumulator in computer science is a container that
stores an intermediate value (remember the processor registers)? As you
can see, it is directly from the Specification.
--
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
Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-16 15:55 -0700
Re: Date Conversion ? Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-17 01:06 +0100
Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-19 12:34 +0100
Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-20 22:29 +0100
Re: Date Conversion ? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-23 10:00 -0200
Re: Date Conversion ? JJ <duh@nah.meh> - 2013-12-17 07:06 +0700
Re: Date Conversion ? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-17 00:35 +0000
Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-16 18:16 -0700
Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-17 10:09 +0100
Re: Date Conversion ? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-17 17:02 +0000
Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-18 19:14 +0000
Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-19 15:42 +0100
Re: Date Conversion ? "Michael F. Stemper" <michael.stemper@gmail.com> - 2013-12-19 09:20 -0600
Re: Date Conversion ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-20 10:04 +0100
Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-17 15:12 +0100
Re: Date Conversion ? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-17 18:10 -0200
Re: Date Conversion ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-17 21:42 +0100
Re: Date Conversion ? Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-18 13:36 +0100
Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-17 19:02 +0000
Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-17 20:51 -0700
Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-19 20:21 +0000
Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-20 09:52 -0700
Re: Date Conversion ? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-21 20:41 +0000
Re: Date Conversion ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-12-22 09:52 -0700
csiph-web