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


Groups > comp.lang.javascript > #29865

Re: Bubblesort

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Bubblesort
Date Wed, 09 Mar 2016 02:41:14 +0100
Organization PointedEars Software (PES)
Lines 91
Message-ID <1680048.scrNnmjT8S@PointedEars.de> (permalink)
References <0d68ee6d-8a80-439e-ae04-17743584e2e4@googlegroups.com> <nbbp99$fed$1@dont-email.me> <XnsA5C17A5C66BA1eejj99@194.109.6.166> <086a7397-459b-46e3-b83c-cfc7edf4188a@googlegroups.com> <7b1ee9db-4732-48e1-be7e-37ba62db4c6e@googlegroups.com> <nbc50g$44d$1@news.albasani.net> <26b2b860-b6c6-40ff-bcf6-64d6a9baa55e@googlegroups.com> <8737s6doyh.fsf@bsb.me.uk> <291513408.Ea4uQbgaIG@PointedEars.de> <87ziu85wvf.fsf@bsb.me.uk>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1457487675 24481 eJwNisERACAIw1ZCbIuOw6HuP4IknzzCqaEKiAJfm5lb2HyDaJLdheXHTYZwWz3VvNctWPoARQ/l (9 Mar 2016 01:41:15 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Wed, 9 Mar 2016 01:41:15 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwFwYEBwDAEBMCVyD9hnCL2H6F3BlfvSzenrW11vVxyY7QK+95gXC/SOWKUb00yXZNE5MTBmdAOPSkN+wFnmxTk
Cancel-Lock sha1:WMg7wNfZak2FYzjLXkmrDOY9FII=
X-NNTP-Posting-Host eJwFwQkBwDAIA0BLK5BQ5FAe/xJ2B+VhuRE0LLbtcFODNdDxezlrKYn172YkJNjnTWupzJsfIcsRng==
Xref csiph.com comp.lang.javascript:29865

Show key headers only | View raw


Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Ben Bacarisse wrote:
>>> jonas.thornvall@gmail.com writes:
>>> <snip>
>>>> Sorry i bothered you your approach do indeed ***work***, apparently it
>>>> is a string but i can't understand how random makes a string value.
>>> 
>>> Math.random() does not make a string but Array.prototype.sort() uses
>>> string comparison by default.  It's documented.
>>
>> Imprecise.
>>
>> String comparison *can* be the default for Array.prototype.sort(); in
>> fact, if the /comparefn/ argument is “undefined” (including not
>> specified), the sort order is *implementation-dependent*. 
>> Implementations need not agree on a default comparator.
> 
> That is not how I read the document you cite.  The default comparator
> *is* specified

Nobody said that the default comparator would not be specified.

> (it's 22.1.3.24.1 with /comparefn/ undefined) and the resulting order is
> only implementation-defined in some rather particular cases.

Including these:

| The sort order is also implementation-defined if comparefn is undefined 
| and SortCompare (22.1.3.24.1) does not act as a consistent comparison 
| function.
| […]
| The sort order is also implementation defined if any of the following 
| conditions are true:
| 
| […]
| · If comparefn is undefined and the application of ToString to any value 
|   passed as an argument to SortCompare modifies obj or any object on 
|   obj’s prototype chain.
| · If comparefn is undefined and all applications of ToString, to any
|   specific value passed as an argument to SortCompare, do not produce the 
|   same result.
| 
| […]
| A function comparefn is a consistent comparison function for a set of 
| values S if all of the requirements below are met for all values a, b, and 
| c (possibly the same value) in the set S: The notation a <CF b means 
| comparefn(a,b) < 0; a =CF b means comparefn(a,b) = 0 (of either sign); and 
| a >CF b means comparefn(a,b) > 0.
| 
| · Calling comparefn(a,b) always returns the same value v when given a 
|   specific pair of values a and b as its two arguments. Furthermore, 
|   Type(v) is Number, and v is not NaN. Note that this implies that exactly
|   one of a <_CF b, a =_CF b, and a >_CF b will be true for a given pair of
|   a and b.
| · Calling comparefn(a,b) does not modify obj or any object on obj’s
|   prototype chain.
| · a =_CF a (reflexivity)
| ­· If a =_CF b, then b =_CF a (symmetry)
| · If a =_CF b and b =_CF c, then a =_CF c (transitivity of =CF)
| · If a <_CF b and b <_CF c, then a <_CF c (transitivity of <CF)
| · If a >_CF b and b >_CF c, then a >_CF c (transitivity of >CF)

| 22.1.3.24.1 Runtime Semantics: SortCompare( x, y )
| […]
| NOTE 2   Method calls performed by the ToString abstract operations in 
|          steps 5 and 7 have the potential to cause SortCompare to not
|          behave as a consistent comparison function.

Those are too many “rather particular cases” for my taste to risk omitting 
the specification of a comparator as argument.

>> So specifying a comparator is *required* in *portable* code *regardless*
>> of the type of the elements (which can be of a different type each; but
>> see Typed Arrays).
> 
> Portable code may properly rely on the specified properties of sort even
> with an undefined /comparefn/.

The specified properties alone do not lead to consistent results among 
implementations, especially not as not all implementations in use are 
conforming.  The record shows.

>> <http://www.ecma-international.org/ecma-262/6.0/index.html#sec-array.prototype.sort>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

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


Thread

Bubblesort jonas.thornvall@gmail.com - 2016-03-04 02:00 -0800
  Re: Bubblesort "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-04 18:53 +0800
    Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-04 12:01 +0100
      Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 03:03 -0800
      Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 05:15 -0800
        Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 05:41 -0800
          Re: Bubblesort "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-04 21:56 +0800
          Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-04 15:10 +0100
            Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 07:37 -0800
              Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-04 17:08 +0100
            Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 07:50 -0800
            Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 07:54 -0800
              Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-04 17:21 +0100
              Re: Bubblesort Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-04 19:26 +0000
                Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-04 23:05 +0100
                Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-05 09:15 -0800
                Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-08 03:43 +0100
                Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-08 02:41 -0800
                Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-08 09:10 -0800
                Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-08 23:34 +0100
                Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-08 23:46 +0100
                Re: Bubblesort Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-09 00:16 +0000
                Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-09 02:41 +0100
            Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-08 23:35 +0100
              Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-09 02:38 +0100
                Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-09 22:04 +0100
                Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-10 21:14 +0100
                Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-10 22:17 +0100
                Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-10 22:31 +0100
                Re: Bubblesort Stefan Weiss <krewecherl@gmail.com> - 2016-03-10 23:25 +0100
                Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-11 00:16 +0100
        Re: Bubblesort "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-04 21:59 +0800
          Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-04 17:12 +0100
          Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-05 02:00 +0100
            Re: Bubblesort John Harris <niam@jghnorth.org.uk.invalid> - 2016-03-05 18:39 +0000
            Re: Bubblesort Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-05 17:40 -0800
      Re: Bubblesort "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-03-04 21:54 +0800
        Re: Bubblesort "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-04 16:59 +0100
    Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 03:04 -0800
      Re: Bubblesort jonas.thornvall@gmail.com - 2016-03-04 03:55 -0800
    Re: Bubblesort Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-05 00:01 +0100
      Re: Bubblesort Aleksandro <aleksandro@gmx.com> - 2016-03-06 18:41 -0300

csiph-web