Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19633

Re: About keeping my array 1 based after having sorted it

From Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: About keeping my array 1 based after having sorted it
Date 2013-05-04 16:14 +0100
Organization Home
Message-ID <KBf07lIKXShRFw38@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <klrbhd$duk$1@dont-email.me> <c0affca3-9adb-40c0-bcdd-3222defbd338@a8g2000yqp.googlegroups.com> <12786665.ZbpLptdNGN@PointedEars.de> <bd93fc08-185a-4614-91c2-a78ea5b6beaa@n11g2000yqe.googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <bd93fc08-185a-4614-91c2-a78ea5b6beaa@n1
1g2000yqe.googlegroups.com>, Fri, 3 May 2013 08:53:40, Scott Sauyet
<scott.sauyet@gmail.com> posted:

>Thomas 'PointedEars' Lahn wrote:
>> Scott Sauyet wrote:
>>> You can probably achieve the same thing with this:
>>
>>>     bookingArray.sort(function(a, b) {
>>>       return a.Objectid < b.Objectid ? -1 :
>>>              a.Objectid > b.Objectid ? +1 :
>>>              new Date(a.Fromtime) - new Date(b.Fromtime);
>>
>> (The “+” in “+1” is a superfluous conversion operation; it is *not* a no-op.
>
>ACK.
>
>But I choose to accept the very minor performance degradation in order
>to keep the code more obvious, stressing that I'm returning a positive
>number in one place and a negative in another.

A sensible system will handle those signs on reading the source or on
first executing the statement.  In any case, the time taken to do one of
those should be negligible in comparison with that taken to do the
function call and return.


>> Also, few people know that “-1” actually is a “unary -” conversion operation
>> on the primitive Number value 1.  See ES 5.1, §§ 11.4.6 and 11.4.7.)
>
>What's your evidence for that?  I'm surprised to learn that few people
>know that.  Do they expect it's simply part of the number literal
>instead?

A script engine is required to give the results which would be given if
the specification was followed literally.  If there is a formal
requirement to follow the specification literally, it will be ignored in
actual browsers where thought beneficial to do so.


-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

About keeping my array 1 based after having sorted it "Tony" <tony.johansson@inport.com> - 2013-05-01 17:18 +0200
  Re: About keeping my array 1 based after having sorted it Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-01 08:26 -0700
    Re: About keeping my array 1 based after having sorted it "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-01 19:43 +0200
      Re: About keeping my array 1 based after having sorted it Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-01 15:15 -0700
        Re: About keeping my array 1 based after having sorted it "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-02 09:35 +0200
          Re: About keeping my array 1 based after having sorted it Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-02 14:31 +0000
      Re: About keeping my array 1 based after having sorted it Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-01 22:12 +0000
        Re: About keeping my array 1 based after having sorted it "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-02 09:36 +0200
  Re: About keeping my array 1 based after having sorted it Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-02 08:52 -0700
    Re: About keeping my array 1 based after having sorted it Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-03 01:26 +0200
      Re: About keeping my array 1 based after having sorted it Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-03 08:53 -0700
        Re: About keeping my array 1 based after having sorted it Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-03 18:39 +0200
          Re: About keeping my array 1 based after having sorted it Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-03 11:00 -0700
            Sorting arrays of objects (was: About keeping my array 1 based after having sorted it) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-05 01:00 +0200
              Re: Sorting arrays of objects (was: About keeping my array 1 based after having sorted it) Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-05 08:53 -0700
        Re: About keeping my array 1 based after having sorted it Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-05-04 16:14 +0100

csiph-web