Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Bubblesort Date: Wed, 09 Mar 2016 00:16:20 +0000 Organization: A noiseless patient Spider Lines: 35 Message-ID: <87ziu85wvf.fsf@bsb.me.uk> References: <0d68ee6d-8a80-439e-ae04-17743584e2e4@googlegroups.com> <086a7397-459b-46e3-b83c-cfc7edf4188a@googlegroups.com> <7b1ee9db-4732-48e1-be7e-37ba62db4c6e@googlegroups.com> <26b2b860-b6c6-40ff-bcf6-64d6a9baa55e@googlegroups.com> <8737s6doyh.fsf@bsb.me.uk> <291513408.Ea4uQbgaIG@PointedEars.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="19095"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CmTcR30tLbpbcRh9UmrGUQVlIQ8eJx2U=" Cancel-Lock: sha1:rRi7xB7I/nzMIGGkx27US0GWdEM= sha1:EZFU3/kJQ4jwiknZqV6ahgmHGg0= X-BSB-Auth: 1.3281a97e8d68c1a5fca6.20160309001620GMT.87ziu85wvf.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:29863 Thomas 'PointedEars' Lahn writes: > Ben Bacarisse wrote: > >> jonas.thornvall@gmail.com writes: >> >>> 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 (it's 22.1.3.24.1 with /comparefn/ undefined) and the resulting order is only implementation-defined in some rather particular cases. > 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/. > -- Ben.